question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

text box with support for raw ansii input

See original GitHub issue

For my app, I really needed to be able to support getting verbatim output from other terminal apps and showing it to the user. These other commands might print color text, and I wanted the color to be preserved and shown to the user as-is. I’ve basically been approaching my asciimatics app as if it were a web app in the terminal; if I were doing a web app, I would be able to use any HTML along with the framework widgets, and I had not considered that a similar way of working with asciimatics and raw ansii codes would be difficult.

I dug around in the asciimatics code for a while and decided that implementing this as a widget would be… pretty difficult, at least for me. My workaround below might be useful for the library documentation.

First we create a new exception to hold the external command to be run and scene to resume once it’s finished:

class ExternalCallException(Exception):
    def __init__(self, last_scene, command):
        self.last_scene = last_scene
        self.command = command

When the external command should be run, we raise the exception like so (self is the widget object):

raise ExternalCallException(self._scene, 'my command here')

Then we add an extra except clause under the one handling screen resizes:

    except ResizeScreenError as e:
        last_scene = e.scene
    # new code below
    except ExternalCallException as e:
        last_scene = e.last_scene
        try:
            # -K means quit on ^C; -R means print ansii codes as-is
            process = Popen(e.command + " | less -K -R", shell=True)
            process.wait()
        except KeyboardInterrupt:
            # let less handle this, -K will exit cleanly
            pass

With this, the external command is piped to less, which temporarily controls the whole screen and shows the command’s output in color. When the user quits less, the app reappears using the same mechanism as when the screen is resized.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
peterbrittaincommented, Jul 6, 2019

The more_colours branch looks like it might be getting close to being a suitable framework. A bit more tidy up to do, then I need to check what happens when I need pass state between parsers. Once I have that working, we can go live.

1reaction
garfieldnatecommented, Dec 31, 2017

One other related feature I would love to have is related to the ability to print raw ansi. I would love to be able to use iTerm’s image display capability. It uses an extension of the ansi escape codes. Even if it’s not the best to have in core asciimatics because it isn’t portable, it would be nice to have a mechanism where I could do this myself (by printing the raw ansi code at some location).

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASCII chars inside textbox - Microsoft Q&A
I have to use a USB hand scanner to scan a code that contains special characters. Unfortunately these are no longer available in...
Read more >
Flat (ascii) Files | Alteryx Help
The flat file type (.flat) is used with ASCII files (.asc) which contain fixed-length fields and optional line ends to mark the end...
Read more >
Validate ASCII - Online ASCII Tools
Incredibly simple, free, and fast browser-based utility for validating ASCII data. Just paste your ASCII symbols and you'll get the ASCII status.
Read more >
The complete table of ASCII characters, codes, symbols and ...
The complete table of ASCII characters, codes, symbols and signs, American Standard Code for Information Interchange, ASCII table, characters, letters, ...
Read more >
- Problem loading the BMF from raw ASCII files
There are several stray characters in the fourth text file of the Business Master File within the field 'ARED' of the organization with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found