Giter VIP home page Giter VIP logo

ledit.asm's Introduction

ledit.asm

A 100% dependency-free terminal line editor, written in x86_64 assembly.

Highlights:

  • Zero dependencies: Not even libc/standard library -- can be dropped into any project and work immediately
  • Basic navigation functionality: Arrow keys, home/end keys (and Ctrl+A/Ctrl-E), backspace, and delete
  • No dynamic memory allocation: Works with static buffers only
  • Tiny: Static library is <2kb in size when stripped

Demo

Demo

Compiling and Running

ledit depends upon nasm. To compile and run the demo application, run:

 $ make demo
 $ ./demo

This will start the line editor. Press Enter to exit.

Using ledit as a readline-like Library

After compiling, the static library ledit.asm.o should be present. To compile a program with ledit, add this to the compiler's list of input files.

Important! Due to the way ledit is written (read: because I am an assembly newbie), any C code must be compiled with -static. For example:

 $ cc my_app.c ledit.asm.o -o my_app -static

To use ledit within C code, define the function ledit() as an extern and define your own syntax() function. The simplest usage is as follows:

#include <unistd.h>  // For write()

extern void ledit(); // Tell compiler to look in ledit.asm.o for ledit

void syntax(char *inp, int inp_len){ // Can be used for syntax highlighting and other text post-processing
  write(STDOUT_FILENO, inp, inp_len);
}

int main(){
  ledit();
  return 0;
}

Some Interesting Implementation Details

  • I rolled my own itoa() in about 35 instructions for this project, see label itoa in ledit.asm for the annotated algorithm.
  • ledit interfaces directly with termios (without the C standard library's tcgetattr() or tcsetattr()), see the beginning of labels ledit and shutdown.
  • See ledit.h for the reference C implementation. Most features in the asm version are 1:1 with the C version, but there some changes (most notably, the lack of sscanf() and printf() in asm, which the C version uses very liberally).

ledit.asm's People

Contributors

cubified avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.