flat assembler
Message board for the users of flat assembler.

Index > Linux > Terminals and escape sequences

Author
Thread Post new topic Reply to topic
0xkorkut



Joined: 10 Mar 2005
Posts: 4
0xkorkut
Programming in linux with FASM is really enjoyable and i thank all who involved in its development.

In fact im new to linux (and assembly Wink ) so i have difficulties in finding info on linux. (googling isnt enough sometimes and sources are not commented for a newbie).

Particularly i want to write console apps for now and i dont want a cursor on my screen. Is there a way (like ioctl) to do this without sending ancient VT100/220 escape sequences (in fact ESC[?25l worked for my box) which are not guarantied to work(?) on every linuxbox.

I currently know linux console is very much different than a VT. I even can't manage to get underlined text. (Same applies for blinking text in console *emulation* Laughing)

I don't want "yo! do this and you'll get what you need." type answers.
Please don't misunderstand me. I'll aprecciate for this type answers but i need to know HOW i can find similar info on my own. If you tell me how do you find it, give me the rod, then i can catch my own fish..

Thanks.

(English is not my native language. I tried to be clear as much as possible.)
Post 10 Mar 2005, 18:34
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
Use curses:

man ncurses
and/or
man curses

There are also info pages (even better). With help of curses library you can write programs like e.g. midnight commander. Read this, learn this, do this and you'll get what you need Smile.
Post 11 Mar 2005, 07:00
View user's profile Send private message Reply with quote
0xkorkut



Joined: 10 Mar 2005
Posts: 4
0xkorkut
hehe
My problem is... I don't want to use any c library .

There should be a way to do this with kernel calls.
Post 11 Mar 2005, 10:32
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
ah so, then just type:

man console_codes

and you get the code list, you can drive the console with. To make your life easy here is an example, which prints an underlined blinking message in red (in xterm at least) to the position (x:25, y:12) of the console.

Just an idea: these are the codes you can also use for your prompt (PS1, PS2, etc.) or in your scripts (see echo) as well, to make them more colorful.

And yes, you have to use ancient control codes, it is not so tragic even when using macros. Linux terminals are compatible with vt100 but additionally have a lot of extra features.

Code:
format  ELF executable
entry   start

        SYSCALL_EXIT    equ 1     ; syscall to function exit()
        SYSCALL_WRITE   equ 4     ; syscall to function write()
        STDOUT          equ 1     ; file descriptor of standard output
        ESC             equ 0x1b  ; escape character

start:
; first clear the screen
        mov     eax, SYSCALL_WRITE
        mov     ebx, STDOUT
        mov     ecx, clear_screen
        mov     edx, clear_screen_size
        int     0x80
; move cursor to (x:25, y:12)
        mov     eax, SYSCALL_WRITE
        mov     ebx, STDOUT
        mov     ecx, move_cursor
        mov     edx, move_cursor_size
        int     0x80
; write the message
        mov     eax, SYSCALL_WRITE
        mov     ebx, STDOUT
        mov     ecx, message
        mov     edx, message_size
        int     0x80
; exit from the program
        mov     eax, SYSCALL_EXIT
        xor     ebx, ebx
        int     0x80

clear_screen: db ESC, "[2J"
clear_screen_size = $ - clear_screen
move_cursor:  db ESC, "[12;25H"
move_cursor_size = $ - move_cursor
message:      db ESC, "[31m", ESC, "[5m", ESC, "[4m" ; red, blink on, underline on
              db "Programming linux is easy", 0xa
              db ESC, "[25m", ESC, "[24m" ; blink off, underline off
message_size = $ - message    
Post 12 Mar 2005, 15:45
View user's profile Send private message Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
Endre: nice example, thanks! Smile
Post 12 Mar 2005, 15:58
View user's profile Send private message Visit poster's website Reply with quote
0xkorkut



Joined: 10 Mar 2005
Posts: 4
0xkorkut
nah.. blink didn't work on GNOME terminal.

nah2.. underline didn't work on real textmode terminal

i think it is something about my own machine

thanks anyway

_________________
.cC}< Eat your veggies >{Cc.
Post 12 Mar 2005, 19:11
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
0xkorkut wrote:
nah.. blink didn't work on GNOME terminal.

nah2.. underline didn't work on real textmode terminal

i think it is something about my own machine

thanks anyway

No, it's not about your machine. It's about different capabilities of different terminals. For instance if a terminal unable to display underlined characters then it still has the right to do something instead of it. For instance underlining is used to emphasize, to highlight something. You can reach something similar if you highlight the given range of the screen in sharp white color, so linux console in text mode do it for you automatically. Another example is that on Sun machines, formerly at least, you had not too much chance to meet with color xterm by default.
The problem is that there are terminals which don't ignore the not interpreted control sequences, but write them out on the screen (quite ugly), so before trying to control a terminal it is necessary to be convinced about its support. And it's not the easiest task without using ncurces and libc, since you have to decide whether the system you run on uses still termcap or already terminfo. Then you have to be able to parse the termcap file or the compiled terminfo files.

Here is a 2-lines color prompt:
Code:
export PS1='\[\033[32m\]\u@\h \[\033[33m\]\w \[\033[0m\]
\$ '    
Post 13 Mar 2005, 11:25
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica
iirc xterm emulates the VT100,VT102, VT220 terminals from DEC and Tektronix 4014. And encording to the man pages:
Code:
 Blinking  characters are partially
       implemented; the emulation is functional but does not have the  appear-
       ance of a real VT102.     
Post 20 Mar 2005, 10:15
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.