You are not logged in.

#1 2010-07-21 17:14:13

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

[SOLVED] Terminal autowrap

For a script I want to turn off autowrap.

E.g. if the terminal is 5 characters wide
Usually:
$ echo $var
reall
ylong
line
$
What I want:
$ echo $var
reall
$

How do I do this? I don't want to check for the length of the line, because it contains escape codes (count towards length but take up zero space) and may also contain UTF (takes up one or two columns but is counted as 1 character or 3 in non-UTF locale).

I tried to use terminfo with things like tput am (automargin), tput smgrp 999 (set right margin with parameter), but they do nothing.

Last edited by Procyon (2010-07-21 19:27:51)

Offline

#2 2010-07-21 17:31:14

karol
Archivist
Registered: 2009-05-06
Posts: 25,428

Re: [SOLVED] Terminal autowrap

Why not counting the chars?
You can run a command before printing the prompt, so maybe you can use this to truncate the output. Not really portable. You would have somehow filter all the escape codes and figure out the widechars.

Edit: Sorry, if my suggestions is insane.

Last edited by karol (2010-07-21 17:38:11)

Offline

#3 2010-07-21 18:04:44

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 987

Re: [SOLVED] Terminal autowrap

echo $var | cut -c -5

edit: oops, you wanted characters, not bytes (changed -b to -c)

Last edited by Trent (2010-07-21 18:06:06)

Offline

#4 2010-07-21 18:10:30

karol
Archivist
Registered: 2009-05-06
Posts: 25,428

Re: [SOLVED] Terminal autowrap

@ Trent
Try to echo this:

echo -e "\033[47m\033[1;37m  White        \033[0m\    1;37m \   \033[40m\033[1;37m  White        \033[0m"

Last edited by karol (2010-07-21 18:14:15)

Offline

#5 2010-07-21 18:18:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,428

Re: [SOLVED] Terminal autowrap

Echo it into the terminal, use xdotool to count 5 chars and delete the rest.

Offline

#6 2010-07-21 18:38:25

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,094
Website

Re: [SOLVED] Terminal autowrap

VT100/ANSI defines '^[7l' and '^[7h' as line wrap off and on, respectively. I couldn't get it to work in urxvt, though.

Offline

#7 2010-07-21 18:41:54

karol
Archivist
Registered: 2009-05-06
Posts: 25,428

Re: [SOLVED] Terminal autowrap

falconindy wrote:

VT100/ANSI defines '^[7l' and '^[7h' as line wrap off and on, respectively. I couldn't get it to work in urxvt, though.

I'm not sure how does a non-wrapping output look like: does it overwrite the previous characters on the same line (i.e. it doesn't go into the next line, but doesn't disappear)?

Offline

#8 2010-07-21 19:01:11

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,094
Website

Re: [SOLVED] Terminal autowrap

It should flow off the screen to the right. If your terminal supported it, you might be offered a horizontal scrollbar.

Offline

#9 2010-07-21 19:27:32

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] Terminal autowrap

karol wrote:

@ Trent
Try to echo this:

echo -e "\033[47m\033[1;37m  White        \033[0m\    1;37m \   \033[40m\033[1;37m  White        \033[0m"

Exactly, it's quite tricky.

falconindy wrote:

VT100/ANSI defines '^[7l' and '^[7h' as line wrap off and on, respectively. I couldn't get it to work in urxvt, though.

Thanks! I googled just line wrap off, and found the right code: ^[[?7l

Offline

#10 2010-07-21 20:41:40

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 987

Re: [SOLVED] Terminal autowrap

Ah, I missed the "escape codes" constraint.

Offline

Board footer

Powered by FluxBB