Demo of an experimental lua-based markup language
Go to file
Kartik K. Agaram c626f30585 Merge template-live-editor 2024-06-16 06:34:16 -07:00
assets bring back assets from old repo 2023-01-03 07:55:38 -08:00
0000-freewheeling-start Merge template-live-editor 2023-04-16 11:30:56 -07:00
0001-on wire up mouse move handler 2023-12-26 08:28:23 -08:00
0002-Debug_animations_in_progress debug animations 2023-11-11 10:00:54 -08:00
0002-vx undo 2 most recent commits 2023-10-25 09:29:22 -07:00
0003-refresh_debug_animations debug animations 2023-11-11 10:00:54 -08:00
0003-scale undo 2 most recent commits 2023-10-25 09:29:22 -07:00
0004-on.update debug animations 2023-11-11 10:00:54 -08:00
0004-vy undo 2 most recent commits 2023-10-25 09:29:22 -07:00
0005-Cursor_node Merge template-live-editor 2023-04-16 11:30:56 -07:00
0005-animate debug animations 2023-11-11 10:00:54 -08:00
0006-loiter debug animations 2023-11-11 10:00:54 -08:00
0006-on.mouse_press space 2023-10-25 09:29:25 -07:00
0007-save_callstack debug animations 2023-11-11 10:00:54 -08:00
0007-to_text undo 2 most recent commits 2023-10-25 09:29:22 -07:00
0008-Debug_animation_period debug animations 2023-11-11 10:00:54 -08:00
0008-Viewport document a desirable invariant 2024-06-16 05:15:01 -07:00
0009-on.code_change Merge template-live-editor 2023-04-16 11:30:56 -07:00
0010-initialize_editor Merge template-live-editor 2023-12-29 15:43:24 -08:00
0011-box_height snapshot: commit 0ca5bb0e8d, take 2 2023-10-25 09:30:50 -07:00
0012-on.initialize undo 2 most recent commits 2023-10-25 09:29:22 -07:00
0013-font Merge template-live-editor 2023-04-16 11:30:56 -07:00
0014-y_of_schema1 bugfix: pin down schema1->y behavior 2023-10-25 00:11:58 -07:00
0015-line_height Merge template-live-editor 2023-04-16 11:30:56 -07:00
0016-schema1_of_y Merge template-live-editor 2023-04-16 11:30:56 -07:00
0017-on.mouse_release backport a few more changes from driver.love 2023-04-22 22:29:22 -07:00
0018-on.update Merge template-live-editor 2023-04-16 11:30:56 -07:00
0019-B snapshot: a whole new approach to panning 2023-10-27 16:07:34 -07:00
0020-Page fix a crash 2023-12-03 13:43:06 -08:00
0021-compute_layout snapshot: a whole new approach to panning 2023-10-27 16:07:34 -07:00
0022-on.text_input bugfix: switch text_input to new panning impl 2023-10-27 23:01:46 -07:00
0023-on.keychord_press clean up debug prints 2023-10-27 18:26:29 -07:00
0024-copy_shape Merge template-live-editor 2023-04-16 11:30:56 -07:00
0025-add_thick_line Merge template-live-editor 2023-04-16 11:30:56 -07:00
0026-on.draw up and down arrow working at all 3 zoom levels 2023-10-27 17:13:28 -07:00
0027-Surface undo 2 most recent commits 2023-10-25 09:29:22 -07:00
0028-A snapshot: a whole new approach to panning 2023-10-27 16:07:34 -07:00
0029-Page2 clean up all the mess since commit fe4e1395d0 2023-10-25 17:59:38 -07:00
0030-update_editor_box bugfix: switch text_input to new panning impl 2023-10-27 23:01:46 -07:00
0031-cols some helpers 2023-06-20 17:34:03 -07:00
0032-rows some helpers 2023-06-20 17:34:03 -07:00
0033-test_y_of_schema1 bugfix: pin down schema1->y behavior 2023-10-25 00:11:58 -07:00
0034-dump_state snapshot: insight 2023-10-25 16:14:08 -07:00
0035-pan_viewport_to_contain_cursor clean up debug prints 2023-10-27 18:26:29 -07:00
LICENSE.txt add a license 2022-05-16 18:51:28 -07:00
Manual_tests.md Merge template-live-editor 2023-12-07 01:25:09 -08:00
MemoryReferenceInfo.lua.0 remove some memory leaks from rendered fragments 2022-06-10 11:16:41 -07:00
MemoryReferenceInfo.lua.unused clean up memory leak experiments 2022-06-10 13:46:59 -07:00
README.md fix a crash involving mouse and drawings 2024-06-09 13:17:55 -07:00
app.lua Merge text0 2024-06-11 12:54:49 -07:00
button.lua bugfix :( 2023-12-18 21:39:01 -08:00
default_map suggest a default layout for freewheeling apps 2023-11-11 10:31:25 -08:00
edit.lua Merge template-live-editor 2024-06-16 06:34:16 -07:00
file.lua audit all asserts 2023-11-18 11:32:01 -08:00
json.lua forgot to add json.lua 2022-05-15 14:36:25 -07:00
keychord.lua support for num pad 2023-07-07 18:40:12 -07:00
live.lua rename a function to be more specific 2023-12-15 15:17:28 -08:00
main.lua Merge template-live-editor 2024-05-20 00:18:40 -07:00
nativefs.lua cleaner API for file-system access 2023-08-30 19:04:06 -07:00
reference.md fix some names in documentation 2024-06-16 05:18:59 -07:00
search.lua Merge text0 2024-06-11 12:54:49 -07:00
select.lua Merge lines.love 2024-06-11 12:13:18 -07:00
test.lua show another detail on test failure 2023-01-20 21:48:49 -08:00
text.lua Merge text0 2024-06-11 12:54:49 -07:00
text_tests bugfix: clear selection when clicking above or below lines 2023-09-20 13:39:29 -07:00
text_tests.lua Merge text0 2024-06-11 12:54:49 -07:00
undo.lua fix a couple of asserts missed in the recent audit 2023-12-09 09:22:45 -08:00

README.md

LuaML: An experimental markup language and 'browser' for it

Demo of a simple structured editor for formatted text atop an infinite 2D surface that can be panned and zoomed.

For ease of implementation, LuaML documents are always legal Lua objects rather than a first-class language like HTML. A simple example:

{ type='text', data={'hello, world!',} }

Text object data consists of an array of strings, one for each line. No newlines at the moment. (Everything is subject to change.)

You can draw various shapes on the surface:

{type='line', data={0,0, 0,600}},
{type='line', data={0,0, 800,0}},
{type='text', data={'0'}, x=-20,y=-20},
{type='rectangle', x=50,y=50, w=20,h=80, r=1,g=0,b=0},
{type='text', data={'abc', 'def'}, x=150, y=50, w=50,h=50, fg={r=0,g=0.4, b=0.9}},
{type='circle', x=300,y=200, radius=40, r=1,g=0,b=1},
{type='arc', x=0,y=0, radius=50, angle1=0, angle2=math.pi*2/3},
{type='ellipse', x=100,y=100, radiusx=10, radiusy=50},
{type='bezier', data={25,25, 25,125, 75,25, 125,25}},

But most of the design effort so far has focused on the 3 text types:

  • text for runs of text to be line-wrapped over the given width.
  • rows and cols, the only hierarchical types, ways to compose text nodes into various grid layouts.

Some more examples.

Adjust foreground/background color (akin to a div with inline style):

{ type='text', fg={r=1,g=0,b=0}, bg={r=1,g=1,b=0},
  data={'hello, world!'}
}

Adjust border color:

{ type='text', border={r=1,g=0,b=0},
  data={'hello, world!'}
}

Rounded corners:

{ type='text', border={r=1,g=0,b=0}, rx=5,ry=5,
  data={'hello, world!'}
}

Two-column text:

{ type='cols', data={
  {type='text', data={'first column'}},
  {type='text', data={'second column'}},
}}

A table with two rows and two columns:

{ type='cols', data={
  { type='rows', data={
    {type='text', data={'abc'}},
    {type='text', data={'def'}},
  }},
  { type='rows', data={
    {type='text', data={'ghi'}},
    {type='text', data={'jkl'}},
  }},
}}

(With the current design, cols of rows seem strictly superior to rows of cols. Column boundaries line up consistently across rows.)

This is still quite incomplete. Come help figure out its future. Currently supported "attributes":

  • fg, bg for color (no blink tag yet)
  • margin (used as margin-left or margin-top depending on whether the parent node has cols or rows respectively)
  • width in pixels (I'd like to add '%' units here.)

Since this is all Lua, unrecognized attributes are silently ignored. In the app itself you'll see attributes like name and doc. (This is a nightmare if you imagine this turning into some sort of long-lived standard with versions and compatibility guarantees. I don't. I just want an app-internal format for creating UIs with very little code.)

This repo is an example of a Freewheeling App, designed above all to be easy to run, easy to modify and easy to share.

Getting started

Install LÖVE. It's just a 5MB download, open-source and extremely well-behaved.

Run the app using LÖVE.

You'll see a page that's currently hard-coded in the app.

initial view

All text is currently editable. There's a table on the right that will grow and shrink as you add and delete text.

Changes you make are currently not saved. This is just a demo.

To pan, drag the surface around. To increase/decrease zoom, press ctrl+=, ctrl+- respectively. To reset zoom press ctrl+0.

Hacking

To edit formatting you'll need to modify the code for the app. To do this live without restarting the app each time, download the driver app. Here's an example session using a fork of this repo:

making changes without restarting the app

Some reference documentation on how to create your own apps.

If the app being modified by the driver lives in a .love file, your changes will go into the save directory. If it lives in a directory (like this repo), your changes will go straight into the same directory.

Keyboard shortcuts

While editing text:

  • ctrl+f to find patterns within a file
  • ctrl+c to copy, ctrl+x to cut, ctrl+v to paste
  • ctrl+z to undo, ctrl+y to redo
  • ctrl+= to zoom in, ctrl+- to zoom out, ctrl+0 to reset zoom
  • alt+right/alt+left to jump to the next/previous word, respectively
  • mouse drag or shift + movement to select text, ctrl+a to select all

When cursor is not in an editor:

  • arrow keys pan the surface
  • shift+arrow keys pan faster
    • pagedown and pageup are aliases for shift+down and shift+up respectively

Exclusively tested so far with a US keyboard layout. If you use a different layout, please let me know if things worked, or if you found anything amiss: http://akkartik.name/contact

Known issues

  • No support yet for Unicode graphemes spanning multiple codepoints.

  • No support yet for right-to-left languages.

  • Undo/redo may be sluggish in editor windows containing large files. Large files may grow sluggish in other ways.

  • If you kill the process, say by force-quitting because things things get sluggish, you can lose data.

  • Can't scroll while selecting text with mouse.

  • No scrollbars yet. That stuff is hard.

Mirrors and Forks

This repo is a fork of lines.love, an editor for plain text where you can also seamlessly insert line drawings. Its immediate upstream is the template repo for freewheeling apps. Updates to it can be downloaded from the following mirrors:

Further forks are encouraged. If you show me your fork, I'll link to it here.

Feedback

Most appreciated.