new fork: carousel shell

akkartik
Nov 15, 2023, 2:07 PM
ZM7NOBRMD5HHA35Y4JDC76EOA2RD4KQOQCPURXYKXA6ABMKOJIGQC

Dependencies

  • [2] QW7YRY25 Merge text0
  • [3] RKRBRQ4Y bugfix: render text in given fg color
  • [4] JOPVPUSA editing source code from within the app
  • [5] 5DOC2CBM extract a function
  • [6] XVR2O5PI change text cursor shape
  • [7] HALS7E5U more clearly skip prints before screen top
  • [8] I64IPGJX avoid saving fragments in lines
  • [9] ULKLJBN6 couple of renames
  • [10] EQSFHYF3 slightly standardize on app-specific stuff
  • [11] Z4XRNDTR find text
  • [12] YJ6ASFBG yet another fork trying to integrate my live framework with everything else
  • [13] RTDYYP4H bugfix: text past cursor was rendered red on wrapped lines
  • [14] AJB4LFRB try to maintain a reasonable line width
  • [15] 2RXZ3PGO beginning of a new approach to scroll+wrap
  • [16] 5OVKHVY6 nice way to make on.* handlers more discoverable
  • [17] H2DPLWMV snapshot: wrapping long lines at word boundaries
  • [18] M7UODV5H Merge text0
  • [19] UBA2ZUCP remove a duplicate print to screen
  • [20] 3TFEAQSW start using some globals
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] V5SYDHPQ start thinking of compute_fragments as a detail
  • [*] OTIBCAUJ love2d scaffold
  • [*] 36Z442IV back to commit 8123959e52f without code editing
  • [*] 3PSFWAIL Merge lines.love
  • [*] 2L5MEZV3 experiment: new edit namespace
  • [*] 4KC7I3E2 make colors easier to edit
  • [*] R5QXEHUI somebody stop me

Change contents

  • edit in text.lua at line 19
    [23.63]
    [4.162]
    App.color(Line_number_color)
    love.graphics.print(line_index, State.left-Line_number_width*App.width('m')+10,y)
    if fg == nil then
    initialize_color()
    end
  • replacement in text.lua at line 70
    [4.2604][4.126:151](),[4.151][3.4:24](),[3.24][4.179:229](),[4.179][4.179:229]()
    -- render fragment
    App.color(fg)
    App.screen.print(screen_line, State.left,y)
    [4.2604]
    [4.1049]
    -- render colorized text
    local x = State.left
    for frag in screen_line:gmatch('%S*%s*') do
    if fg then
    App.color(fg)
    else
    select_color(frag)
    end
    App.screen.print(frag, x,y)
    x = x+App.width(frag)
    end
  • edit in main.lua at line 36
    [25.2189]
    [26.23433]
    Line_number_width = 3 -- in ems
  • replacement in main.lua at line 69
    [4.102][4.81:112](),[4.81][4.81:112]()
    love.window.setTitle('TODO')
    [4.102]
    [4.7]
    love.window.setTitle('Carousel Shell')
  • edit in main.lua at line 146
    [2.930]
    [2.930]
    App.screen.width = love.window.fromPixels(App.screen.width)
    App.screen.height = love.window.fromPixels(App.screen.height)
  • edit in edit.lua at line 5
    [28.839]
    [28.997]
    Line_number_color = {r=0.4, g=0.4, b=0.4}
  • edit in edit.lua at line 15
    [25.7970]
    [27.436]
    require 'colorize'
  • file addition: colorize.lua (----------)
    [29.2]
    -- State transitions while colorizing a single line.
    -- Just for comments and strings.
    -- Limitation: each fragment gets a uniform color so we can only change color
    -- at word boundaries.
    Next_state = {
    normal={
    {prefix='--[[', target='block_comment'}, -- only single-line for now
    {prefix='--', target='comment'},
    -- these don't mostly work well until we can change color within words
    -- {prefix='"', target='dstring'},
    -- {prefix="'", target='sstring'},
    {prefix='[[', target='block_string'}, -- only single line for now
    },
    dstring={
    {suffix='"', target='normal'},
    },
    sstring={
    {suffix="'", target='normal'},
    },
    block_string={
    {suffix=']]', target='normal'},
    },
    block_comment={
    {suffix=']]', target='normal'},
    },
    -- comments are a sink
    }
    Comment_color = {r=0, g=0, b=1}
    String_color = {r=0, g=0.5, b=0.5}
    Divider_color = {r=0.7, g=0.7, b=0.7}
    Colors = {
    normal=Text_color,
    comment=Comment_color,
    sstring=String_color,
    dstring=String_color,
    block_string=String_color,
    block_comment=Comment_color,
    }
    Current_state = 'normal'
    function initialize_color()
    --? print('new line')
    Current_state = 'normal'
    end
    function select_color(frag)
    --? print('before', '^'..frag..'$', Current_state)
    switch_color_based_on_prefix(frag)
    --? print('using color', Current_state, Colors[Current_state])
    App.color(Colors[Current_state])
    switch_color_based_on_suffix(frag)
    --? print('state after suffix', Current_state)
    end
    function switch_color_based_on_prefix(frag)
    if Next_state[Current_state] == nil then
    return
    end
    frag = rtrim(frag)
    for _,edge in pairs(Next_state[Current_state]) do
    if edge.prefix and starts_with(frag, edge.prefix) then
    Current_state = edge.target
    break
    end
    end
    end
    function switch_color_based_on_suffix(frag)
    if Next_state[Current_state] == nil then
    return
    end
    frag = rtrim(frag)
    for _,edge in pairs(Next_state[Current_state]) do
    if edge.suffix and ends_with(frag, edge.suffix) then
    Current_state = edge.target
    break
    end
    end
    end
  • file addition: 0019-Line_number_padding (----------)
    [29.2]
    Line_number_padding = 0
  • file addition: 0017-on.mouse_release (----------)
    [29.2]
    on.mouse_release = function(x,y, mouse_button)
    edit.mouse_release(Editor_state, x,y, mouse_button)
    end
  • file addition: 0016-on.mouse_press (----------)
    [29.2]
    on.mouse_press = function(x,y, mouse_button)
    edit.mouse_press(Editor_state, x,y, mouse_button)
    end
  • file addition: 0015-on.key_release (----------)
    [29.2]
    on.key_release = function(key, scancode)
    edit.key_release(Editor_state, key, scancode)
    end
  • file addition: 0014-on.text_input (----------)
    [29.2]
    on.text_input = function(t)
    edit.text_input(Editor_state, t)
    end
  • file addition: 0013-on.keychord_press (----------)
    [29.2]
    on.keychord_press = function(chord, key)
    edit.keychord_press(Editor_state, chord, key)
    end
  • file addition: 0012-on.draw (----------)
    [29.2]
    on.draw = function()
    love.graphics.rectangle('line', 100-5-Line_number_padding,100-5, 400+10, 200+10, 5,5)
    edit.draw(Editor_state)
    end
  • file addition: 0011-on.initialize (----------)
    [29.2]
    on.initialize = function()
    love.graphics.setFont(love.graphics.newFont(20))
    Line_height = math.floor(love.graphics.getFont():getHeight()*1.3)
    Line_number_padding = Line_number_width*App.width('m')
    Editor_state = edit.initialize_state(100, 100, 400, love.graphics.getFont():getHeight(), Line_height)
    Text.redraw_all(Editor_state)
    end
  • file addition: 0010-Line_height (----------)
    [29.2]
    Line_height = 0
  • file addition: 0009-Editor_state (----------)
    [29.2]
    Editor_state = nil