All pastes #338148 Raw Edit

Untitled

public text v1 · immutable
·published 2007-02-03 06:08 UTC
rendered paste body
proc format_speed {value section} {
	global speedmeasure speedthreshold theme

	if {[string is double $value]} {
		switch -exact -- [string tolower $speedmeasure] {
			"mb" {
				set value [format "%.2f" [expr {$value / 1024.0}]]
				set type $theme(MB)
			}
			"kbit" {
				set value [expr {$value * 8}]
				set type $theme(KBIT)
			}
			"mbit" {
				set value [format "%.1f" [expr {$value * 8 / 1000.0}]]
				set type $theme(MBIT)
			}
			"autobit" {
				if {$value > $speedthreshold} {
					set value [format "%.1f" [expr {$value * 8 / 1000.0}]]
					set type $theme(MBIT)
				} else {
					set value [expr {$value * 8}]
					set type $theme(KBIT)
				}
			}
			"autobyte" {
				if {$value > $speedthreshold} {
					set value [format "%.2f" [expr {$value / 1024.0}]]
					set type $theme(MB)
				} else {
					set type $theme(KB)
				}
			}
			"disabled" {
				return $value
			}
			default {
				set type $theme(KB)
			}
		}
	}

	return [themereplace [replacevar $type "%value" $value] $section]
}