#!/usr/bin/wish # tkbuffer - buffered entry for X11, with multiline hold mode and history set title "(no target)" set history [list] set histindex 0 set hold 0 proc retarget {} { global wid title set wid [exec xdotool selectwindow] set title [exec xdotool getwindowname $wid] } proc submit {} { global wid history histindex set str [.entry get 1.0 end] exec xdotool type --clearmodifiers --window $wid $str .entry delete 1.0 end lappend history [string range $str 0 end-1] set histindex [expr [llength $history]] } button .retarget -text "Target" -command retarget label .title -textvariable title text .entry -width 80 -height 5 bind .entry { set hold [expr !$hold] if $hold { .entry configure -foreground #009 } else { .entry configure -foreground #000 submit } } bind .entry { if !$hold { submit break } } bind .entry { .entry delete 1.0 end } bind .entry { .entry delete 1.0 end if {$histindex>0} {set histindex [expr $histindex-1]} .entry insert end [lindex $history $histindex] break } bind .entry { .entry delete 1.0 end if {$histindex<[llength $history]} {set histindex [expr $histindex+1]} .entry insert end [lindex $history $histindex] break } grid .retarget .title -sticky w grid .entry - grid columnconfigure . .entry -weight 1 grid rowconfigure . .entry -weight 1 #pack .entry -fill both -expand yes -side right focus .entry