Tcl/Tk: horizontal xscrollbar can not shrink as y scollbar - scrollbar

In the following example code:
proc push_button {} {
set name [.ent get]
.txt insert end "Hello, $name."
}
frame .frm -relief groove
label .lab -text "Enter name:"
entry .ent
button .but -text "Push Me" -command "push_button"
frame .textarea
text .txt -width 20 -height 10 \
-yscrollcommand ".srl_y set" -xscrollcommand ".srl_x set"
scrollbar .srl_y -command ".txt yview" -orient v
scrollbar .srl_x -command ".txt xview" -orient h
pack .lab -in .frm
pack .ent -in .frm
pack .frm
pack .but
grid .txt -in .textarea -row 1 -column 1
grid .srl_y -in .textarea -row 1 -column 2 -sticky ns
grid .srl_x -in .textarea -row 2 -column 1 -sticky ew
pack .textarea
Push the button Push Me, new text string will be added into the textbox. And in .txt insert end "Hello, $name." there is no new line \n symbol. So it should form a very long string.
My understanding is as the string goes longer, the horizontal scollbar should change and shrink correspondingly. But xscollbar can not work as expected.
I need such effect in my tool. So any help on this?

The behaviour you are experiencing is because of text wrapping. The default text wrapping mode seems to be char (the text will be split into more lines when the width limit is reached, and it will split on a character basis).
Change the following line to get the behaviour you were expecting to see:
text .txt -width 20 -height 10 \
-yscrollcommand ".srl_y set" -xscrollcommand ".srl_x set" -wrap none
I added -wrap none to the end.

Related

How to Change Appearance of Text in ChUI Editor Widget

I'm using an editor widget to display a longchar value read from a text file. OpenEdge 11.5 ChUI on Linux.
The logic is similar to the following:
def var mytext as longchar
init "Sample Text. Sample Text. Sample Text.".
form mytext view-as editor large inner-chars 30 inner-lines 15
scrollbar-horizontal scrollbar-vertical
with frame frame1 no-labels no-box.
view frame frame1.
display mytext with frame frame1.
mytext:read-only = yes.
enable mytext with frame frame1.
wait-for end-error of mytext.
When the editor is displayed, the text in the editor widget is "highlighted" (i.e., shown in reverse video). (See screenshot below.)
Is there a way to display the text in the editor widget so that it is not "highlighted"?
I usually do something like this:
/* textedit.p
*
* a file viewer
*
*/
define variable fileName as character no-undo format "x(30)".
define variable fileBody as longchar no-undo.
fileName = "textedit.p".
file-info:file-name = fileName.
if file-info:full-pathname = ? then
do:
message "no such file:" fileName.
pause.
quit.
end.
copy-lob from file file-info:full-pathname to fileBody.
display
fileBody view-as editor inner-chars 160 inner-lines 52 large no-word-wrap
with
no-box
no-labels
color display normal prompt normal /* this changes the coloring */
.
pause.
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/color-phrase.html
You can also fiddle with frame and widget attributes if you prefer that sort of thing.

UNIX awk : Print line with "CLICKS", if * on pos 7 skip line, if contain "\" concat next line, if next line has * concat 3rd line

I need to print line from file which contains "CLICK" and are not commented (* on position 7) like line 000001,
if the line has CLICK and "\" then concatenate the next line too , if next line is commented then skip that line and concatenate the next one : like line number 000002 concat with line 000004 skipping line 000003.
if concatenated line (next) also contains '\' then we do not need to concat the 3rd line, by which i mean we do Delete the line from the output, like we deleted the lines 3 and 5 because they are not required
the core logic as stated previously:
[if the line has CLICK and "\" (both) then concatenate the next line, if line only has CLICK print that line only,everything other line is deleted from output ] .
so in this case example is:
000006 concats line 000007 but do not concats 000008 which means 000008 will be deleted from the output
INPUT FILE:
000001 HECTOR CLICK MOUSE
000002 ANNE CLICK MOUSE \
000003* AND PRESSES KEYBOARD
000004 AND PRESS KEYBOARD
000005* CLARK CLICK MOUSE
000006 MIKE CLICK MOUSE \
000007 AND PRESS KEYBOARD \
000008 AND TAPS SCREEN
output
000001 HECTOR CLICK MOUSE
000002 ANNE CLICK MOUSE \ AND PRESS KEYBOARD
000006 MIKE CLICK MOUSE \ AND PRESS KEYBOARD \
I have created this :
awk '
/^...... +/{
if ($0 ~ /CLICK/ && $0 ~ /\\/)
{l1=$0;getline; print l1 $0}
else if
($0 ~ /CLICK/ && $0 !~ /\\/)
{print $0} ;
}' *> outfile
the outcome is quite close but there are two problems :
1. the data is written twice
2. commented second line is also printed, i tried /^...... +/ inside the if but it gave error
$ cat tst.awk
$1 ~ /\*$/ { next }
saved != "" {
sub(/^[^[:space:]]*[[:space:]]+/," ")
print saved $0
saved = ""
}
/CLICK/ {
if ( /\\$/ ) {
saved = $0
}
else {
print
}
}
$ awk -f tst.awk file
000001 HECTOR CLICK MOUSE
000002 ANNE CLICK MOUSE \ AND PRESS KEYBOARD
000006 MIKE CLICK MOUSE \ AND PRESS KEYBOARD \
Skip every comment line. For every other line: When we find a line containing CLICK, if it ends in backslash then save it, otherwise print it. For every line, if we have a saved string then print it in front of the current line. The sub() is to change the leading number and spaces into a single blank char before printing the current line at the end of the saved line.

Split line into multiple lines of 42 Unix after last given char

I have a text file in unix formed from multiple long lines
ALTER Tit como(titel('42423432;434235111;757567562;2354679;5543534;6547673;32322332;54545453'))
ALTER Mit como(Alt('432322;434434211;754324237562;2354679;5543534;6547673;32322332;54545453'))
I need to split each line in multiple lines of no longer than 42 characters.
The split should be done at the end of last ";", and
so my ideal output file will be :
ALTER Tit como(titel('42423432;434235111; -
757567562;2354679;5543534;6547673; -
32322332;54545453'))
ALTER Mit como(Alt('432322;434434211; -
754324237562;2354679;5543534;6547673; -
32322332;54545453'))
I used fold -w 42 givenfile.txt | sed 's/ $/ -/g'
it splits the line but doesnt add the "-" at the end of the line and doesnt split after the ";".
any help is much appreciated.
Thanks !
awk -F';' '
w{
print""
}
{
w=length($1)
printf "%s",$1
for (i=2;i<=NF;i++){
if ((w+length($i)+1)<42){
w+=length($i)+1
printf";%s",$i
} else {
w=length($i)
printf"; -\n%s",$i
}
}
}
END{
print""
}
' file
This produces the output:
ALTER Tit como(titel('42423432;434235111; -
757567562;2354679;5543534;6547673; -
32322332;54545453'))
ALTER Mit como(Alt('432322;434434211; -
754324237562;2354679;5543534;6547673; -
32322332;54545453'))
How it works
Awk implicitly loops through each line of its input and each line is divided into fields. This code uses a single variable w to keep track of the current width of the output line.
-F';'
Tell awk to break fields on semicolons.
`w{print""}
If the last line was not completed, w>0, then print a newline to terminate it before we start with a new line.
w=length($1); printf "%s",$1
Print the first field of the new line and set w according to its length.
Loop over the remaining fields:
for (i=2;i<=NF;i++){
if ((w+length($i)+1)<42){
w+=length($i)+1
printf";%s",$i
} else {
w=length($i)
printf"; -\n%s",$i
}
}
This loops over the second to final fields of this line. Whenever we reach the point where we can't print another field without exceeding the 42 character limit, we print ; -\n.
END{print""}
Print a newline at the end of the file.
This might work for you (GNU sed):
sed -r 's/.{1,42}$|.{1,41};/& -\n/g;s/...$//' file
This globally replaces 1 to 41 characters followed by a ; or 1 to 42 characters followed by end of line with -\n. The last string will have three characters too many and so they are deleted.

Extract texts from a single file and writing those texts to multiple files

I'm trying to achieve the following.
Find first '(' symbol (always located at the start of a new line) in a text file and make the hostname that follows a variable such as '(host' becomes 'host'.
Copy text between first instance of '=-=-=' delimiter and second instance of the same delimiter ('=-=-=') to a new file whose name is the variable in item 1 such as host-messages.txt
Copy text between second instance of '=-=-=' delimiter and third instance of the same delimiter to a new file whose name is the variable in item 1 such as host-df.txt
Copy text between third instance of '=-=-=' delimiter and subsequent next instance of a '(' on the first character of a new line such as the next instance of a '(hostname',to a new file whose name is the variable in item such as host-dfa.txt
Repeat steps 1 through 4 until end of file and no more '(host' are found.
Anyway what I'm trying to achieve is extract data such as:
(hostname1 : 056603)  1
=-=-=
TEXT
TEXT
TEXT
=-=-=
TEXT2
TEXT2
TEXT2
=-=-=
TEXT3
TEXT3
TEXT3
(hostname2
=-=-=
etc...
Newly created files should be hostname1-messages.txt, hostname1-df.txt and hostname1-dfa.txt.
The best I've come up with so far is
awk '/=-=-=/{x="F"++i;next}{print > x;}' test.txt
but it's not working.
Post some sample input and expected output to help us help you but something like this is what you want (untested, obviously):
awk '
BEGIN{ sfx[1]="-messages.txt"; sfx[2]="-df.txt"; sfx[3]="-dfa.txt" }
sub(/^\(/,"") { host=$0; nr=0; next }
/=-=-=/ { nr++; next }
{ print > host sfx[nr] }
' file

Multiline Text in Flex 4

In Flex I want to create a Text file and it is working, but the problem is all inputs are written in one line;
here the cods
addText.text="[ \r\n"
addText.text=addText.text+"] \r\n";
fileRef.save(addText.text, "data.txt");
the current result is like below;
[]
how can I make it like this;
[
]
i would start trying
addTextxt.text = "[ \n ]";
it normally works in all cases...
good luck ( :

Resources