ctext(3tk)

πŸ“¦
version 0.9 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ ctext β€” the text widget that's literally so extra (and we love her for it) ✨

okay bestie so this one is from the ctext manual page in section 3tk of tklib β€” it's the glow-up of your regular text widget, and honestly? she ate. πŸ’…


πŸ¦‹ NAME πŸ¦‹

ctext β€” Ctext, a text widget with highlighting support. that's it, that's the name, no cap. πŸ’–


🌸 SYNOPSIS 🌸

package require Tk

package require ctext ?3.3?

ctext pathName ?options?

::ctext::addHighlightClass pathName class color keywordlist

::ctext::addHighlightClassWithOnlyCharStart pathName class color char

::ctext::addHighlightClassForSpecialChars     pathName    class    color
charstring

::ctext::addHighlightClassForRegexp pathName class color pattern

::ctext::clearHighlightClasses pathName

::ctext::getHighlightClasses pathName

::ctext::deleteHighlightClass pathName class

::ctext::enableComments enable

::ctext::disableComments enable

pathName highlight startIndex endIndex

pathName fastdelete index1 ?index2?

pathName fastinsert

pathName copy

pathName cut

pathName paste

pathName append

pathName configure option value ?...?

like look at that whole list, she's serving range πŸ’…βœ¨


πŸ‘‘ DESCRIPTION πŸ‘‘

the ctext package hands you the ctext widget, which is an enhanced text widget with support for configurable syntax highlighting plus a couple of extra commands. it's giving main character energy for real. πŸ”₯

Ctext overloads the text widget and provides new commands, named highlight, copy, paste, cut, append, and edit. it also provides several commands that let you define classes. each class corresponds to a tag in the widget. πŸŽ€


πŸ’– COMMANDS πŸ’–

  • ctext pathName ?options? β€” creates and configures a ctext widget. that's the whole vibe right there. 🫢

🌈 HIGHLIGHTING 🌈

okay so this is the part that's genuinely iconic. highlighting is controlled with text widget tags, and those tags are called highlight classes. a class is a tag name and can be configured like any text widget tag. four types of highlight classes are supported. all highlight classes are automatically used by the highlight method of the widget. iykyk. ✨

  • ::ctext::addHighlightClass pathName class color keywordlist β€” adds a highlighting class class to the ctext widget pathName. the highlighting is done with the color color. all words in the keywordlist get highlighted. obsessed.
# highlight some tcl keywords
::ctext::addHighlightClass .t tclkeywords red [list set info interp uplevel upvar]
  • ::ctext::addHighlightClassWithOnlyCharStart pathName class color char β€” adds a highlighting class class to the ctext widget pathName. the highlighting is done with the color color. every word that starts with char gets highlighted. lowkey so useful. πŸ‘‘
::ctext::addHighlightClassWithOnlyCharStart .t vars blue \$
  • ::ctext::addHighlightClassForSpecialChars pathName class color charstring β€” adds a highlighting class class to the ctext widget pathName. the highlighting is done with the color color. every char in charstring gets highlighted. ✨
  • ::ctext::addHighlightClassForRegexp pathName class color pattern β€” adds a highlighting class class to the ctext widget pathName. the highlighting is done with the color color. every text part that matches the regexp pattern gets highlighted. regex girlies rise 🧚
  • ::ctext::clearHighlightClasses pathName β€” removes all highlight classes from the widget pathName. total reset, fresh start, new era. πŸ’€
  • ::ctext::getHighlightClasses pathName β€” lists all highlight classes for the widget pathName. show me what you got. πŸ“
  • ::ctext::deleteHighlightClass pathName class β€” deletes the highlight class class from the widget pathName. bye bestie πŸ‘‹
  • ::ctext::enableComments enable β€” enables C comment highlighting. the class for c-style comments is _cComment. the C comment highlighting is disabled by default. πŸ™ˆ
  • ::ctext::disableComments enable β€” disables C comment highlighting.

πŸ’… WIDGET COMMANDS πŸ’…

every ctext widget you create with the command up above supports these commands and options on top of the standard text widget commands and options. she does everything the regular one does, just with more flair. ✨

  • pathName highlight startIndex endIndex β€” highlights the text between startIndex and endIndex. 🌈
  • pathName fastdelete index1 ?index2? β€” deletes a text range without updating the highlighting. the arguments are identical to the pathName delete command inherited from the standard text widget.
  • pathName fastinsert β€” inserts text without updating the highlighting. the arguments are identical to the pathName insert command inherited from the standard text widget.
  • pathName copy β€” calls tk_textCopy for the ctext instance. πŸ“‹
  • pathName cut β€” calls tk_textCut for the ctext instance. βœ‚οΈ
  • pathName paste β€” calls tk_textPaste for the ctext instance. 🫢
  • pathName append β€” appends the current selection to the clipboard.
  • pathName configure option value ?...? β€” sets the options for the ctext widget. each option name must be followed by the new value. one option, one value, no skipping. periodt. πŸ’…

πŸŽ€ WIDGET OPTIONS πŸŽ€

heads up: every one of these has a Database Name and a Database Class slot, and both of them are left blank in this doc β€” so it's just the command-line switch doing the talking. πŸ’–
  • Command-Line Switch: -linemap
    • Database Name: (blank)
    • Database Class: (blank)

creates (-linemap 1) or deletes (-linemap 0) a line number list on the left of the widget. the default is to have a linemap displayed. ✨

  • Command-Line Switch: -linemapfg
    • Database Name: (blank)
    • Database Class: (blank)

changes the foreground of the linemap. the default is the same color as the main text widget. 🎨

  • Command-Line Switch: -linemapbg
    • Database Name: (blank)
    • Database Class: (blank)

changes the background of the linemap. the default is the same color as the main text widget. 🌸

  • Command-Line Switch: -linemap_select_fg
    • Database Name: (blank)
    • Database Class: (blank)

changes the selected line foreground. the default is black. πŸ–€

  • Command-Line Switch: -linemap_select_bg
    • Database Name: (blank)
    • Database Class: (blank)

changes the selected line background. the default is yellow. πŸ’›

  • Command-Line Switch: -linemap_mark_command
    • Database Name: (blank)
    • Database Class: (blank)

calls a procedure or command with the pathName of the ctext window, the type β€” which is either marked or unmarked β€” and finally the line number selected. the proc prototype is:

proc linemark_cmd {win type line}.

see also ctext_test_interactive.tcl. πŸ‘€

  • Command-Line Switch: -highlight
    • Database Name: (blank)
    • Database Class: (blank)

takes a boolean value which defines whether or not to highlight text which is inserted or deleted. the default is 1. πŸ”₯

  • Command-Line Switch: -linemap_markable
    • Database Name: (blank)
    • Database Class: (blank)

takes a boolean value which specifies whether or not lines in the linemap are markable with the mouse. the default is 1. πŸ–±οΈ


⭐ EXAMPLE ⭐

okay this is the whole thing, and yes you're gonna copy it, no shame in that, we all do it:

package require Tk
package require ctext

proc main {} {
pack [frame .f] -fill both -expand 1
pack [scrollbar .f.s -command {.f.t yview}] -side right -fill y

pack [ctext .f.t -bg black -fg white -insertbackground yellow  -yscrollcommand {.f.s set}] -fill both -expand 1

ctext::addHighlightClass .f.t widgets purple  [list ctext button label text frame toplevel  scrollbar checkbutton canvas listbox menu menubar menubutton  radiobutton scale entry message tk_chooseDir tk_getSaveFile  tk_getOpenFile tk_chooseColor tk_optionMenu]

ctext::addHighlightClass .f.t flags orange  [list -text -command -yscrollcommand  -xscrollcommand -background -foreground -fg -bg  -highlightbackground -y -x -highlightcolor -relief -width  -height -wrap -font -fill -side -outline -style -insertwidth  -textvariable -activebackground -activeforeground -insertbackground  -anchor -orient -troughcolor -nonewline -expand -type -message  -title -offset -in -after -yscroll -xscroll -forward -regexp -count  -exact -padx -ipadx -filetypes -all -from -to -label -value -variable  -regexp -backwards -forwards -bd -pady -ipady -state -row -column  -cursor -highlightcolors -linemap -menu -tearoff -displayof -cursor  -underline -tags -tag]

ctext::addHighlightClass .f.t stackControl red  {proc uplevel namespace while for foreach if else}
ctext::addHighlightClassWithOnlyCharStart .f.t vars mediumspringgreen "\$"
ctext::addHighlightClass .f.t variable_funcs gold {set global variable unset}
ctext::addHighlightClassForSpecialChars .f.t brackets green {[]{}}
ctext::addHighlightClassForRegexp .f.t paths lightblue {\.[a-zA-Z0-9\_\-]+}
ctext::addHighlightClassForRegexp .f.t comments khaki {#[^\n\r]*}
.f.t fastinsert end [info body main]

pack [frame .f1] -fill x

.f.t highlight 1.0 end

pack [button .f1.exit -text Exit -command exit] -side left

pack [entry .e] -side bottom -fill x
.e insert end "ctext::deleteHighlightClass .f.t "
bind .e <Return> {eval [.e get]}
}
main

further examples are in the source package for ctext. go dig, bestie πŸ”


🫢 THANKS 🫢

Kevin Kenny, Neil Madden, Jeffrey Hobbs, Richard Suchenwirth, Johan Bengtsson, Mac Cody, GΓΌnther, Andreas Sievers, and Michael Schlenker.

the way these legends carried this whole thing, we stan πŸ˜­πŸ’–


πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

this document, and the package it describes, will undoubtedly contain bugs and other problems. please report such in the category ctext of the Tklib Trackers [http://core.tcl.tk/tklib/reportlist]. please also report any ideas for enhancements you may have for either package and/or documentation. don't be shy, the maintainers wanna hear it fr fr. πŸ™ˆ


🌈 SEE ALSO 🌈

re_syntax, text


🌟 KEYWORDS 🌟

syntax highlighting, text, widget


Copyright (c) George Peter Staplin <GeorgePS@XMission.com>


and that's the whole page, bestie β€” this one's tklib version 3.3, dated right alongside ctext(3tk), so if you see 3.3 floating around, that's your girl. go highlight something gorgeous. βœ¨πŸŽ€πŸ’…πŸ¦‹

πŸ“¦ where this page comes from