Opened 9 years ago

Last modified 23 months ago

#4361 assigned bug

more command don't work as expected

Reported by: phoudoin Owned by: nobody
Priority: normal Milestone: R1
Component: Applications/Command Line Tools Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: x86

Description

$ less /etc/resolv.conf
nameserver 192.168.1.1
$ more /etc/resolv.conf
$ 

Seems that the more command line tool doesn't work fine. Native Haiku, x86-gcc4-hybrid, clean build, hrev32762. But I saw this issue since few months already, should have report it sooner.

Attachments (1)

0001-fix-less-and-more-bug-see-track-ticket-4361.patch (615 bytes) - added by eanyx 5 years ago.
patch to fix less and more problem ticket #4361

Download all attachments as: .zip

Change History (22)

comment:1 Changed 9 years ago by jackburton

Actually, more doesn't work if the file has only one line. I tested with

more /var/log/syslog

And I got the full output.

comment:2 Changed 9 years ago by jackburton

Hmm more testing shows that more is indeed, pretty broken. I can't scroll to the end of a file because it exits before 100%.

comment:3 Changed 9 years ago by axeld

Since less works fine, I guess this could be one of those positive error codes problems. At least it would be worth a try.

comment:4 Changed 9 years ago by jackburton

What's also interesting is that "more" is just a link to "less".

comment:5 in reply to:  4 Changed 9 years ago by phoudoin

Replying to jackburton:

What's also interesting is that "more" is just a link to "less".

But it doesn't behave the same, as less detect when he's called "more" and set "less_is_more" global flag.

comment:6 Changed 9 years ago by jackburton

Yep, I just noticed :)

comment:7 Changed 9 years ago by korli

It seems also reproducible with "less -F". When commenting the following lines in init() and deinit() in screen.c, the problem disappears.

tputs(sc_init, sc_height, putchr);

tputs(sc_deinit, sc_height, putchr);

comment:8 Changed 9 years ago by phoudoin

Sounds like Terminal tty don't support setting its height, no?

comment:9 Changed 9 years ago by korli

Adding these lines in /etc/profile workarounds this bug:

export LESS=-X
export MORE=-X

comment:10 Changed 5 years ago by jessicah

Wow, still not fixed! Just got caught out testing viewing my patch, wondering why my file modified with sed/grep ended up apparently empty... argh :(

comment:11 Changed 5 years ago by jessicah

From what I've seen on Linux, more doesn't clear what it's printed, whereas less does. However, I did notice that less -E results in no output despite a file containing less than a screenful of text. So it seems the less_is_more mode on Haiku might need to also change the terminal emulation behaviour as well.

comment:12 Changed 5 years ago by siarzhuk

BTW, Ctrl-Alt-C shortcut can be used to capture all characters and control codes sent by program into Terminal as raw stream. Corresponding capture log will be stored under /var/log/ The shortcut works as toggle switch - pressing it starts the capture, the next press will stop the capture.

comment:13 in reply to:  11 Changed 5 years ago by siarzhuk

Replying to korli:

It seems also reproducible with "less -F". When commenting the following lines in init() and deinit() in screen.c, the problem disappears.

tputs(sc_init, sc_height, putchr);

tputs(sc_deinit, sc_height, putchr);

Those are

enter_ca_mode      smcup     ti       string to start programs using cup
[...]
exit_ca_mode       rmcup     te       strings to end programs using cup

and defined in XTERM to set/unset DEC private mode 1049

CSI ? 1049h  → Save cursor as in DECSC and use Alternate Screen Buffer, clearing it first.
[...]
CSI ? 1049l  →  Use Normal Screen Buffer and restore cursor as in DECRC.

This explains observed behaviour of the 'more' program - all output just goes to alternate screen buffer and is not visible on normal buffer after the program finishes. The 'less' has the chance to show its output to user because it waits until the key pressed at the EOF. In both cases the output is not visible in the Terminal history after the programs finish.

Replying to jessicah:

From what I've seen on Linux, more doesn't clear what it's printed, whereas less does. However, I did notice that less -E results in no output despite a file containing less than a screenful of text. So it seems the less_is_more mode on Haiku might need to also change the terminal emulation behaviour as well.

Could you compare the less source code on your Linux with Haiku's one, check current values of ti/te (in case termcap used) or smcup/rmcup (in case terminfo) and LESS/MORE environment variables? Are there any ways to preset the less options?

comment:14 Changed 5 years ago by kallisti5

this may explain why in vim if you open a long file and scroll around eventually the lines displayed don't match what is "really" under your cursor.

This occurs in terminal, but running vim through ssh on your Haiku machine works fine.

comment:15 in reply to:  14 Changed 5 years ago by siarzhuk

Replying to kallisti5:

this may explain why in vim if you open a long file and scroll around eventually the lines displayed don't match what is "really" under your cursor.

I do not think so - all above described more/less behaviour works as it should in this configuration and environment. te/ti set to switch writing into alternate buffer so it is correct to not write anything into the Terminal history.

So you observe different issue, I think.

This occurs in terminal, but running vim through ssh on your Haiku machine works fine.

Do you meant haiku system accesed through ssh from non-haiku system? Can you say me more exactly how to reproduce the problem with console vim?

Changed 5 years ago by eanyx

patch to fix less and more problem ticket #4361

comment:16 Changed 5 years ago by eanyx

Has a Patch: set

comment:17 Changed 5 years ago by mmu_man

As korli mentionned 4 years ago it's actually a workaround and doesn't fix the actual problem. more definitely prints something, it just doesn't wait for input and clears the screen immediately.

comment:18 Changed 5 years ago by mmu_man

For the record, here is what both give in Debugger:

~> hd more.out.txt 
00000000   1b 5b 3f 31 30 34 39 68  1b 5b 3f 31 68 1b 3d 0a   .[?1049h.[?1h.=. 
00000010   75 73 65 72 3a 78 3a 30  3a 30 3a 59 6f 75 72 73   user:x:0:0:Yours 
00000020   65 6c 66 3a 2f 62 6f 6f  74 2f 68 6f 6d 65 3a 2f   elf:/boot/home:/ 
00000030   62 69 6e 2f 62 61 73 68  0a 0a 1b 5b 4b 1b 5b 3f   bin/bash...[K.[? 
00000040   31 6c 1b 3e 1b 5b 3f 31  30 34 39 6c 20 20 20 20   1l.>.[?1049l.... 

~> hd less.out.txt 
00000000   1b 5b 3f 31 30 34 39 68  1b 5b 3f 31 68 1b 3d 0a   .[?1049h.[?1h.=. 
00000010   75 73 65 72 3a 78 3a 30  3a 30 3a 59 6f 75 72 73   user:x:0:0:Yours 
00000020   65 6c 66 3a 2f 62 6f 6f  74 2f 68 6f 6d 65 3a 2f   elf:/boot/home:/ 
00000030   62 69 6e 2f 62 61 73 68  0a 1b 5b 37 6d 2f 65 74   bin/bash..[7m/et 
00000040   63 2f 70 61 73 73 77 64  20 28 45 4e 44 29 1b 5b   c/passwd.(END).[ 
00000050   32 37 6d 1b 5b 4b 0a 0a  0a 0a 1b 5b 4b 1b 5b 3f   27m.[K.....[K.[? 
00000060   31 6c 1b 3e 1b 5b 3f 31  30 34 39 6c 0a 0a 20 20   1l.>.[?1049l.... 

comment:19 Changed 5 years ago by mmu_man

Odd, doing an ssh to a linux box, more works as expected in Terminal, but copying the linux xterm terminfo file to ~/.terminfo/x/ doesn't work though.

comment:20 Changed 4 years ago by waddlesplash

Has a Patch: unset

comment:21 Changed 23 months ago by axeld

Owner: changed from axeld to nobody
Status: newassigned
Note: See TracTickets for help on using tickets.