Giter Site home page Giter Site logo

warfley / laztermutils Goto Github PK

View Code? Open in Web Editor NEW
26.0 5.0 4.0 45 KB

Terminal utility classes for FPC and Lazarus on Windows and Unix that provide the functionality of the CRT unit and more

License: BSD 2-Clause "Simplified" License

Pascal 100.00%
lazarus fpc freepascal console console-application terminal linux windows-10 windows unix pascal

laztermutils's Introduction

LazTermUtils

Terminal Utility Classes for Coloring and Inputs on terminals

About

This small library contains a few classes for managing terminal I/O using ANSI escape sequences. The goal of this unit is provide the functionality provided by the CRT unit (and some more), but optimized for only the most prevalent systems, by only using escape sequences. It was tested under Windows 10 and Linux and allows for writing portable, pretty console applications on both systems.

The functionality include:

  • Colorizing output (background, foreground)
  • Modifying output (bold, italic, underlined, etc.)
  • Reading input keys and modifiers
  • Managing terminal window (getting size, jumping around, clearing)
  • Non blocking reading of chars and keys

Requirements

This library uses xTerm compatible ANSI escape sequences.

This works with any Terminal emulator supporting this including, but not limited to xTerm, Konsole, GNOME Terminal and the Windows Terminal in Windows 10 (not compatible with older versions of Windows) If the terminal does not support 24 bit (true) color (e.g. the macOS system terminal emulator), you might want to set the define Col8 (only required in TerminalColor.pas), which limits the output to 8bit colors. Lower than that is not supported.

Usage

See the example directory for some examples.

  • example/ReadkeyExample shows how to read Keystrokes and process them
  • example/Colortest colors the whole display (each cell individually) while measuring the FPS to brenchmark the performance of redrawing every cell
  • example/Textmods prints text with different modifications. Which of them get displayed correctly depends on your Terminal emulator.
  • example/NonBlockingReadTest shows how to use non blocking read to update your view and check for keystrokes single threaded

Unicode on Windows

To use unicode (UTF-8) strings on Windows, you need to set the console code page:

  SetConsoleOutputCP(DefaultSystemCodePage);
  SetTextCodePage(Output, DefaultSystemCodePage);
  SetTextCodePage(ErrOutput, DefaultSystemCodePage);

Further information can be found here: https://wiki.freepascal.org/Lazarus_with_FPC3.0_without_UTF-8_mode#Problem_System_encoding_and_Console_encoding_.28Windows.29

laztermutils's People

Contributors

warfley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laztermutils's Issues

Feature request: support for cmd.exe console

Hello,

as you state, this package only works with Windows Terminal of Win10. It would, however, be incredibly useful if the classic Windows console which is provided by cmd.exe/conhost.exe could be supported as well.

Even some basic support (i.e. without colors or other fancy things, just cursor positioning and writing) would be welcome. :)

TTerminal object appears to be leaking memory

Hello and thank you for this great project!

Just wanted to report that TTerminal objects don't appear to be freeing up all allocated memory. Sample code below compiled with "fpc -gh".

`
program LazTermUtilsExample;

{$MODE OBJFPC} {$LONGSTRINGS ON}

uses Terminal;

var
term : TTerminal;

begin
term := TTerminal.create;
term.free;
end.
`

Output:

$ ./LazTermUtilsExample

Heap dump by heaptrc unit of /tmp/LazTermUtilsExample
33 memory blocks allocated : 2689/2704
32 memory blocks freed : 2649/2664
1 unfreed memory blocks : 40
True heap size : 393216
True free heap : 392960
Should be : 392984
Call trace for block $00007FB50F0F7200 size 40
$0000000000498C3B
$000000000048156F
$0000000000429B17
$00000000004295AA
$00000000004010B2

Thanks!

Special Key modifier

The modifiers (alt, meta, ctrl) don't currently work for some special keys (arrows, home, end), because the automaton can not recognize [CSI]1;[MOD][CHAR]

Similar issue as faced with F1-F4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.