blt::htext(3tcl)
β¨ htext β create and manipulate hypertext widgets π
okay bestie, buckle up, this one's from the BLT Built-In Commands set (the manual page lives as blt::htext(3tcl)), and it's literally the blueprint for the hypertext widget. it's giving "text widget that went to geometry-manager school". let's go π
πΈ NAME πΈ
htext β Create and manipulate hypertext widgets
π SYNOPSIS π
htext pathName ?option value?...
π¦ DESCRIPTION π¦
okay so the htext command makes a whole new window (that's your pathName argument, bestie) and turns it into an htext widget. you can also pass extra options, described above, either on the command line or in the option database, to configure stuff like its color and font. important: at the moment you invoke this command, there must not already be a window named pathName β but pathName's parent must exist. and then htext hands you back its pathName. slay.
the htext widget is a hybrid β no cap β of a non-editable text widget and a geometry manager (like, think the packer). it displays text (optionally read from a file) in a window. you can scroll that text either horizontally or vertically, using the htext window as a viewport. and it gets better: Tcl commands can be embedded right into the text, and they get evaluated as the text is parsed. any text sitting between the special double characters (by default, percent signs %%) gets immediately passed to the Tcl interpreter to be evaluated. iconic behaviour tbh.
plus β and this is the main character energy part β any widget or widget hierarchy can be packed in-line and made to appear on the current line of the text. widgets get packed using the htext append command. all widgets must be children of the htext window and must already exist before packing. once a widget has been packed it cannot be moved to a different position within the text. widgets can be resized, but they'll stay at the same position within the text. periodt.
here's a lil fact that saves you so much grief: before a file or text string is parsed by the htext widget, all the widget's current children are destroyed. so you can reload files or text without worrying about unmapping or destroying each child window beforehand. we love a self-cleaning king π«Ά
setting either the -filename or -text configuration option will adjust the value of the other. if both options are set, the file takes precedence. when a new file is read using the -filename option, the value of the -text option is reset to the empty string. likewise, when the -text option is set, the string representing the -filename option is cleared. (they're linked, bestie, one always cancels the other out π)
π FILE FORMAT π
the format of an htext text file is typically ASCII text. text enclosed by special double characters (by default, percent signs %%) is interpreted and executed as Tcl commands. the special character can be specified by the -specialchar option.
in the following example of a htext file, a button widget is appended to the text between the words "a" and "which". the pathName of the htext widget is .ht.
This will be displayed as normal text.
But this will become a %%
button .ht.button -text "button" -fg red
.ht append .ht.button
%% which can invoke a Tcl command.
π§ INDICES π§
some of the widget operations (selection, gotoline, search, etc.) take one or more indices as arguments. an index is just a string that points at a particular place within the text β like, say, the first and last characters in a range you wanna select. π
an index must have one of the following forms:
line.charβ indicates the char'th character on line line. both lines and characters are numbered from 0, so"0.0"is the very first beginning of the text. char may be undesignated β in that case a character position of 0 is assumed.@x,yβ indicates the character that covers the pixel whose x and y coordinates within the text's window are x and y.endβ indicates the end of the text.anchorβ indicates the anchor point for the selection, which is set with the selection operation.sel.firstβ indicates the first character in the selection. it's an error to use this form if the selection isn't in the entry window. πsel.lastβ indicates the character just after the last one in the selection. it's an error to use this form if the selection isn't in the entry window.
π VARIABLES π
the following global Tcl variables are maintained when an htext file is parsed:
htext(widget)β is the pathname of the htext widget.htext(file)β is the name of the file the htext widget is currently parsing. it is the empty string when the-textoption is used.htext(line)β is the current line number in the text.
this information might be used to construct hyper links between different files and/or lines. iykyk β¨
β SYNTAX β
the htext command creates a new Tcl command whose name is pathName. this command may be used to invoke various operations on the widget. it has the following general form:
pathName oper ?args?
Oper and args determine the exact behavior of the command.
π OPERATIONS π
the following operations are available for htext widgets:
pathName append window ?option value?...β embeds the widget window into the htext widget. window is the pathname of the widget to be embedded, which must be a child ofpathName. window will be positioned in the htext widget at the current location of the text. if option and value pairs are present, they configure various aspects of how window appears inpathName. the following options are available:-anchoranchorPos β specifies how window will be arranged if there's any extra space in the cavity surrounding the window. for example, if anchorPos iscenterthen the window is centered in the cavity; if anchorPos iswthen the window will be drawn such that it touches the leftmost edge of the cavity. the default iscenter.-fillstyle β specifies how the window should be stretched to occupy the extra space in the cavity surrounding it (if any exists). style isnone,x,y,both. if style isx, the width of window is expanded to fill the cavity. if style isy, the height is expanded. the default isnone.-heightpixels β sets the height of the cavity surrounding window. if pixels is zero, the height of the cavity will be the same as the requested height of window. if pixels is less than the requested height of window, window will be reduced to fit the cavity. the default is0.-ipadxpad β sets the amount of internal padding to be added to the width of window. pad can be a list of one or two numbers. if pad has two elements, the left side of window is extended by the first value and the right side by the second value. if pad is just one value, both the left and right sides are padded evenly by the value. the default is0.-ipadypad β sets an amount of internal padding to be added to the height of window. pad can be a list of one or two numbers. if pad has two elements, the top of window is padded by the first value and the bottom by the second value. if pad is just one number, both the top and bottom are padded evenly by the value. the default is0.-justifyjustify β justifies window vertically within the cavity containing it in relation to the line of text. justify istop,bottom, orcenter. if justify iscenterthe widget is centered along the baseline of the line of text. the default iscenter.-padxpad β sets the padding on the left and right sides of window. pad can be a list of one or two numbers. if pad has two elements, the left side of window is padded by the first value and the right side by the second value. if pad has just one value, both the left and right sides are padded evenly by the value. the default is0.-padypad β sets the padding above and below window. pad can be a list of one or two numbers. if pad has two elements, the area above window is padded by the first value and the area below by the second value. if pad is just one number, both the top and bottom are padded by the value. the default is0.-relheightvalue β specifies the height of the cavity containing window relative to the height ofpathName. value is a real number indicating the ratio of the height of the cavity to the height ofpathName. as the height ofpathNamechanges, so will the height of window. if value is0.0or less, the height of the cavity is the requested height of window. the default is0.0.-relwidthvalue β specifies the width of the cavity containing window relative to the width ofpathName. value is a real number indicating the ratio of the width of the cavity to the width ofIpathName. as the height ofpathNamechanges, so will the height of window. if value is0.0or less, the width of the cavity is the requested width of window. the default is0.0.-widthvalue β species the width of the cavity containing the child window. value must be in a form accepted byTk_GetPixels. if value is greater than zero, the cavity is resized to that width. if the requested window width is greater than the cavity's width, the window will be reduced to fit the cavity. by default, the cavity is the requested width of the child window.
pathName configure ?window? ?option? ?value option value ...?β queries or modifies the configuration options of the text widget or one of its embedded widgets. if no window argument is present, the htext widget itself is configured. otherwise window is the pathname of a widget already embedded into the htext widget β and then this command configures the options for the embedded widget.
if option isn't specified, a list describing all of the current options for pathName or window is returned. if option is specified, but not value, then a list describing the option option is returned. if one or more option and value pairs are specified, then for each pair, the htext or embedded window option option is set to value.
the following options are valid for the htext widget.
β¨ OPTIONS β¨
okay so these are the options, bestie. Each one is a little knob you can turn to make your htext widget do the thing. Slay. π
-background colorβ sets the background of the htext widget to color. The default is white. So clean. β¨-cursor cursorβ picks the cursor for the htext widget. The default cursor is pencil βοΈ. It's giving study buddy.-filename fileNameβ tells the widget which htext file to display. If you set it to the empty string (""), then the-textoption is used instead. No cap. For the full tea on the file format, check the FILE FORMAT section. π-font fontNameβ sets the font of the text in the htext widget tofontName. The default is*-Helvetica-Bold-R-Normal-*-12-120-*. Periodt. π-foreground colorβ sets the foreground of the htext widget to color. This is literally the color of the text. The default is <black>black</black>. π€-height pixelsβ specifies the height of the htext widget window. In pixels, bestie. π-linespacing pixelsβ specifies the spacing between each line of text. The value must be in a form accepted byTk_GetPixels. The default value is1pixel. So cozy. π§΅-specialchar numberβ specifies the ASCII value of the special double character delimiters. In htext files, the text between these special characters is evaluated as a block of Tcl commands. The default special character is0x25(the percent sign). It's giving magic. β¨-text textβ specifies the text to be displayed in the htext widget. Text can be any valid string of characters. See FILE FORMAT for the description. π-xscrollcommand stringβ specifies the prefix for a command used to communicate with horizontal scrollbars. When the view in the htext widget's window changes (or whenever anything else occurs that could change the display in a scrollbar, such as a change in the total size of the widget's contents), the widget invokesstringconcatenated by two numbers. Each of the numbers is a fraction between0and1, which indicates a position in the document. If this option is not specified, then no command will be executed. π-yscrollcommand stringβ specifies the prefix for a command used to communicate with vertical scrollbars. When the view in the htext widget's window changes (or whenever anything else occurs that could change the display in a scrollbar, such as a change in the total size of the widget's contents), the widget invokesstringconcatenated by two numbers. Each of the numbers is a fraction between0and1, which indicates a position in the document. If this option is not specified, then no command will be executed. β¬οΈβ¬οΈ-width pixelsβ specifies the desired width of the viewport window. Ifpixelsis less than one, the window will grow to accommodate the widest line of text. Flexible queen. π-xscrollunits pixelsβ specifies the horizontal scrolling distance. The default is10pixels. βοΈ-yscrollunits pixelsβ specifies the vertical scrolling distance. The default is10pixels. βοΈ
β¨ COMMANDS β¨
now the commands, bestie. These are how you actually talk to your widget. π¬
pathName gotoline ?index?β sets the top line of the text toindex.indexmust be a valid text index (the character offset is ignored). If an index isn't provided, the current line number is returned. πpathName scan mark positionβ recordspositionand the current view in the text window; used in conjunction with laterscan dragtocommands.positionmust be in the form@x,y, wherexandyare window coordinates. Typically this command is associated with a mouse button press in the widget. It returns an empty string. π±οΈpathName scan dragto positionβ computes the difference betweenpositionand the position registered in the lastscan markcommand for the widget. The view is then adjusted up or down by 10 times the difference in coordinates. This command can be associated with mouse motion events to produce the effect of dragging the text at high speed through the window.positionmust be in the form@x,y, wherexandyare window coordinates. The command returns an empty string. πpathName search pattern ?from? ?to?β returns the number of the next line matchingpattern.patternis a string which obeys the matching rules ofTcl_StringMatch.fromandtoare text line numbers (inclusive) which bound the search. If no match forpatterncan be found,-1is returned. πpathName xview ?position?β moves the viewport horizontally to the new text x-coordinateposition.positionis the offset from the left side of the text to the current position and must be in a form accepted byTk_GetPixels. Ifpositionis not present, the current text position is returned. βοΈpathName yview ?position?β moves the viewport vertically to the new text y-coordinateposition.positionis the offset from the top of the text to the current position and must be in a form accepted byTk_GetPixels. Ifpositionis not present, the current text position is returned. βοΈ
π BUGS π
Text with embedded tabs can be obscured by child windows when scrolled horizontally. Not the vibe, but we move. π
π KEYWORDS π
hypertext, widget
and that's the whole page, bestie! this was from BLT 2.5, blt::htext(3tcl). love u, bye! πβ¨π¦
π¦ where this page comes from
- debian bookworm: blt-dev 2.5.3+dfsg-4.1
- debian trixie: blt-dev 2.5.3+dfsg-8
- ubuntu jammy: blt-dev 2.5.3+dfsg-4.1build2
- ubuntu noble: blt-dev 2.5.3+dfsg-7build1
- ubuntu questing: blt-dev 2.5.3+dfsg-8
- ubuntu resolute: blt-dev 2.5.3+dfsg-8build1
- ubuntu stonking: blt-dev 2.5.3+dfsg-9
- Copyright 1991-1997 by Bell Labs Innovations for Lucent Technologies
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms