0

How would one capture the escape sequences as they are sent by a terminal application (say Konsole for example) ? For example, if you hit PgDown, what is sent to the virtual console ?

I would like to record the byte stream sent to the virtual console (like when I hit "Ctrl+C" what escape sequence it produced) to a file I can then read with hexdump.

hl037_
  • 3,520
  • 1
  • 27
  • 58
  • Possible duplicate of [Logging terminal while running an install script of sorts](https://stackoverflow.com/questions/6350046/logging-terminal-while-running-an-install-script-of-sorts) – Thomas Dickey Oct 07 '17 at 11:49
  • no, theis question provide information about what a script write etc. to log its execution. Here, I want to get the byte stream sent to the virtual console. – hl037_ Oct 08 '17 at 18:11
  • You just read your stdin normally. Escape sequences are a part of the stream. BTW Ctrl-C is not an escape sequence, it's a single character. – n. m. could be an AI Oct 08 '17 at 18:38

1 Answers1

1

I did a small python script to do the trick :

#!/bin/env python

import curses
from pprint import pprint

buf = ''

def main(stdscr):
  global buf
  curses.noecho()
  curses.raw()
  curses.cbreak()
  stdscr.keypad(False)

  stop = stdscr.getkey()
  c = stdscr.getkey()
  buf = ''
  while c != stop:
    buf += c
    c = stdscr.getkey()

def run():
  curses.wrapper(main)
  pprint(buf)
  tmp = buf.encode('latin1')
  pprint([hex(x) for x in tmp])
  pprint([bin(x) for x in tmp])

run()

...It clear the screen, then type a key (e.g. a), then, type any thing, and type the same key as the first one to stop. Then, it will display all the bytes received (example : a [start recording] Alt+b [stop recording] a produces the bytes : ['0x1b', '0x62'] with my terminal

hl037_
  • 3,520
  • 1
  • 27
  • 58