[code] Textadept-curses for WIN32: Good News

From: Gavin Holt <holtgavin.att.gmail.com>
Date: Thu, 9 Jan 2020 09:51:51 +0000

Hi

I am really enjoying TextAdept-curse.exe under WIN32. So far I have tackled
a few of the limitations related to use in the windows console and want to
share some good news:

1) I added winapi to allow access the system clipboard:

    Finding compatible binary libraries is difficult but
https://github.com/shawnye/LuaBinaries4Windows seems to work.
    Find winapi53.dll and save as winapi.dll in your userdata\modules
folder.
    winapi53.dll is dependent upon Lua53.dll which needs to be in the
folder containing Textadept-curses.exe.
    You can get a usable copy of Lua53.dll from
https://sourceforge.net/projects/luabinaries/files/latest/download

    init.lua
    winapi = require("winapi")

    keys['cc'] = function() -- Ctrl+C EditCopy
        buffer:copy()
        winapi.set_clipboard(ui.clipboard_text)
    end

    keys['cx'] = function() -- Ctrl+X EditCut
        buffer:cut()
        winapi.set_clipboard(ui.clipboard_text)
    end

    keys['cv'] = function() -- Ctrl+V EditPaste
        -- Get the system clipboard
        local text = winapi.get_clipboard()
        if text then
            buffer:copy_text(text:gsub('\n\r','\n'))
            buffer:paste()
        end
    end
    -- TODO: Alter other paste functions e.g. in TUI dialogues and command
entry

    I have only tested this dll for cut/copy/paste

2) I have changed the console colours using ColorTool.exe:

    https://github.com/Microsoft/Terminal/tree/master/src/tools/ColorTool

    Execute from within textadept-curse:
    ColorTool.exe -q TextAdeptColours.ini

    TextAdeptColours.ini
    [table]
    DARK_BLACK = 55,57,66
    DARK_BLUE = 0,132,188
    DARK_GREEN = 79,161,79
    DARK_CYAN = 9,150,179
    DARK_RED = 228,86,0
    DARK_MAGENTA = 166,37,164
    DARK_YELLOW = 192,132,0
    DARK_WHITE = 250,250,250
    BRIGHT_BLACK = 79,82,93
    BRIGHT_BLUE = 97,175,239
    BRIGHT_GREEN = 152,195,121
    BRIGHT_CYAN = 86,181,193
    BRIGHT_RED = 223,108,117
    BRIGHT_MAGENTA = 197,119,221
    BRIGHT_YELLOW = 221,154,255
    BRIGHT_WHITE = 255,255,255

    [screen]
    FOREGROUND = DARK_BLACK
    BACKGROUND = DARK_WHITE

    [popup]
    FOREGROUND = BRIGHT_YELLOW
    BACKGROUND = DARK_BLUE

    I did find a bug in colortool as it shrinks the console window with
each call
    (https://github.com/microsoft/terminal/issues/3698).

    If you call colortool.exe once from textadept-curses, then reset the
layout size
    and close the window it will remember the colours and the layout.

    I like a visible caret line, the caret line uses BRIGHT_YELLOW above -
which is actually a restful pink :)
    buffer.caret_line_visible = true

3) I have worked round those key codes not passed on by the console - with
Autohotkey:

    I always have Autohotkey (https://www.autohotkey.com/ ver1.0.48.05)
running
    so this hack is easily tolerated by adding to my master AHK script.

    Master.ahk
    ; **TextAdept enhancements
    #IfWinActive, Administrator: TextAdept
    {

    ; AutoPairs - is off in my configuration of textadept

        ^'::send ''{Left}
        ^2::send ""{Left}
        ^9::send (){Left}
        ^0::send (){Left}
        ^[::Send []{Left}
        ^]::Send []{Left}
        ^5::send `%`%{Left}
        ^+[::Send {{}{}}{Left}
        ^+]::Send {{}{}}{Left}

    ; I like Ctrl+/ to enter command mode
        ^/::send !c

    ; Some console key codes don't work - so pipe through autohotkey as f11
        ^m:: Send {F11}m
        ^+b:: Send {F11}b
        ^+e:: Send {F11}e
        ^+f:: Send {F11}f
        ^+k:: Send {F11}k
        ^+s:: Send {F11}s
    }

    init.lua
    -- Set title - so AutoHotKey can find the window
    io.popen("title TextAdept-curses "..' 2>&1')

    -- Some console key codes don't work - so pipe through autohotkey as f11
    -- e.g. Ctrl+M , Control+Shift+?
    keys['f11'] = {
        m = func.find, -- Ctrl+m Find in editor...a
function I am developing
        b = buffer.vc_home_extend, -- Ctrl+Shift+B SelectEOL
        e = buffer.line_end_extend, -- Ctrl+Shift+E SelectEOL
        f = ui.find.find_incremental, -- Ctrl+Shift+F Incremental Find
        j = keys['msm'], -- Ctrl+Shift+J Select Brace
TODO: FAILS
        k = buffer.del_line_left, -- Ctrl+Shift+k DeleteBOL
        s = io.save_file_as, -- Ctrl+Shift+S FileSaveAs TODO:
Check for legal filenames
    }

I hope other users will find these tips useful

Kind Regards Gavin Holt

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Thu 09 Jan 2020 - 04:51:51 EST

This archive was generated by hypermail 2.2.0 : Thu 09 Jan 2020 - 06:55:05 EST