commandline-info

Kurze Kommandozeilen-Ausgabe in ein anwenderfreundliches Fenster. Beispielsweise Lüfterdrehzahl und Temperatur der CPU:

commandline-info.tcl sensors

Bei jedem Mausklick erneuert sich der Inhalt.


#!/usr/bin/tclsh

package require Tk
bind [winfo class .] <Destroy> exit
namespace import ::tcl::mathop::*

tcl::tm::path add ~/bin/TM

# set argv df

package require History
# source ~/bin/TM/history-0.1.tm

set history [obj new history -unique true]

if {$argv eq ""} then {
  set argv Spruchweisheit.tcl
  set font Monospace
} elseif {[lindex $argv 0] eq "-font"} then {
  set argv [lassign $argv - font]
} else {
  set font Monospace
}

exec echo font $font &

proc setText str {
  variable font
  .info configure -text $str
  if {[regexp {(^|\n) } $str]} then {
    .info configure -font Monospace
  } else {
    .info configure -font $font
  }
  set str
}

event add <<Forward>> <Down> <Right> <Button-5>
event add <<Backward>> <Up> <Left> <BackSpace> <Button-4>

pack [label .info\
      -font $font\
      -bg white\
      -justify left]
$history add [setText [string trim [exec {*}$argv] \n]]
wm resizable . no no
wm title . $argv

bind .info <Button-3> "tk_popup [menu .info.copy -tearoff no] %X %Y"
.info.copy add command -label copy -command {
  clipboard clear
  clipboard append [.info cget -text]
}

bind .info <Button-1> {
  $history add [setText [string trim [exec {*}$argv] \n]]
}

bind . <Key-Return> {
  event generate .info <Button-1>
}
bind . <<Backward>> {
  if {![$history atStart]} then {
    setText [$history back]
  }
  break
}
bind . <<Forward>> {
  if {![$history atEnd]} then {
    setText [$history forward]
  } else {
    # event generate .info <Button-1>
  }
}


12.10.2022