2024-10-29 19:20:58 +00:00
|
|
|
#!/usr/bin/env wish
|
|
|
|
|
2024-10-29 19:58:49 +00:00
|
|
|
package require textutil
|
|
|
|
|
2024-10-29 19:48:50 +00:00
|
|
|
set active_transform 0
|
|
|
|
|
|
|
|
proc oneline {text} {
|
|
|
|
return [regsub -all \n+ $text " "]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc wordcount {text} {
|
|
|
|
set lines [expr [llength [split $text \n]] - 1]
|
|
|
|
set words [llength [regexp -all -inline {\S+} $text]]
|
|
|
|
set len [string length $text]
|
|
|
|
|
|
|
|
lappend out $lines
|
|
|
|
lappend out $words
|
|
|
|
lappend out $len
|
|
|
|
return $out
|
|
|
|
}
|
|
|
|
|
2024-10-29 19:58:49 +00:00
|
|
|
proc dedent {text} {
|
|
|
|
return [textutil::undent $text]
|
|
|
|
}
|
|
|
|
|
2024-10-29 19:50:22 +00:00
|
|
|
proc markdown_quote {text} {
|
2024-11-03 10:47:53 +00:00
|
|
|
set text [string trim $text]
|
2024-10-29 19:50:22 +00:00
|
|
|
return [string cat "> " [regsub -all \n $text "\n> "]]
|
|
|
|
}
|
|
|
|
|
2024-10-29 20:02:17 +00:00
|
|
|
proc identity {text} { return $text }
|
|
|
|
|
|
|
|
lappend transforms [list {None} identity]
|
2024-10-29 19:48:50 +00:00
|
|
|
lappend transforms [list {One line} oneline]
|
|
|
|
lappend transforms [list {Line/Word/Char} wordcount]
|
2024-10-29 19:58:49 +00:00
|
|
|
lappend transforms [list {Dedent} dedent]
|
2024-10-29 19:50:22 +00:00
|
|
|
lappend transforms [list {Markdown Quote} markdown_quote]
|
2024-10-29 19:48:50 +00:00
|
|
|
|
2024-10-29 19:20:58 +00:00
|
|
|
wm geometry . 750x650
|
|
|
|
wm title . "Text Tools"
|
2024-10-29 20:04:08 +00:00
|
|
|
wm resizable . false false
|
2024-10-29 19:20:58 +00:00
|
|
|
|
|
|
|
text .content
|
|
|
|
text .output
|
2024-10-29 19:27:01 +00:00
|
|
|
listbox .transform
|
|
|
|
|
2024-10-29 19:48:50 +00:00
|
|
|
foreach {elem} $transforms {
|
|
|
|
.transform insert end [lindex $elem 0]
|
|
|
|
}
|
|
|
|
.transform selection set $active_transform
|
2024-10-29 19:27:01 +00:00
|
|
|
|
|
|
|
grid .transform -row 1 -column 1 -rowspan 2
|
|
|
|
grid .content -row 1 -column 2
|
|
|
|
grid .output -row 2 -column 2
|
|
|
|
|
2024-10-29 19:20:58 +00:00
|
|
|
focus .content
|
|
|
|
|
2024-10-29 19:48:50 +00:00
|
|
|
proc update_output {} {
|
|
|
|
global active_transform
|
|
|
|
global transforms
|
2024-10-29 19:20:58 +00:00
|
|
|
|
2024-10-29 19:48:50 +00:00
|
|
|
set text [.content get 1.0 end]
|
2024-10-29 19:20:58 +00:00
|
|
|
|
2024-10-29 19:48:50 +00:00
|
|
|
set tf [lindex $transforms $active_transform]
|
|
|
|
set out [[lindex $tf 1] $text]
|
2024-10-29 19:20:58 +00:00
|
|
|
.output replace 1.0 end $out
|
|
|
|
}
|
|
|
|
|
2024-10-29 19:48:50 +00:00
|
|
|
bind .content <KeyRelease> update_output
|
2024-11-03 10:49:25 +00:00
|
|
|
bind . <Escape> exit
|
2024-10-29 19:20:58 +00:00
|
|
|
|
2024-10-29 19:48:50 +00:00
|
|
|
proc select_transform {args} {
|
|
|
|
global active_transform
|
|
|
|
set active_transform [.transform curselection]
|
|
|
|
update_output
|
2024-10-29 19:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bind .transform <Button-1> select_transform
|
|
|
|
|
2024-10-29 19:20:58 +00:00
|
|
|
update
|