more tweaks

This commit is contained in:
kepler155c@gmail.com
2020-04-03 18:56:55 -06:00
parent 6bb4149113
commit f655cc5965

View File

@@ -17,7 +17,6 @@ local tLines = { }
local fileInfo local fileInfo
local lastAction local lastAction
local actions local actions
local sStatus = ''
local lastSave local lastSave
local dirty = { y = 1, ey = h } local dirty = { y = 1, ey = h }
local mark = { } local mark = { }
@@ -26,29 +25,25 @@ local undo = { chain = { }, pointer = 0 }
local complete = { } local complete = { }
local page local page
h = h - 2 h = h - 1
local color = { local color = {
textColor = '0', textColor = '0',
keywordColor = '4', keywordColor = '4',
commentColor = 'd', commentColor = 'd',
stringColor = 'e', stringColor = 'e',
bgColor = colors.black, statusColor = colors.gray,
highlightColor = colors.orange, panelColor = colors.cyan,
cursorColor = colors.lime,
errorBackground = colors.red,
} }
if not term.isColor() then if not term.isColor() then
color = { color = {
textColor = '0', textColor = '0',
keywordColor = '8', keywordColor = '8',
commentColor = '8', commentColor = '8',
stringColor = '8', stringColor = '8',
bgColor = colors.black, statusColor = colors.white,
highlightColor = colors.lightGray, panelColor = colors.white,
cursorColor = colors.white,
errorBackground = colors.gray,
} }
end end
@@ -117,11 +112,12 @@ local keyMapping = {
[ 'control-n' ] = 'find_next', [ 'control-n' ] = 'find_next',
-- misc -- misc
-- [ 'control-g' ] = 'status', [ 'control-i' ] = 'status',
[ 'control-r' ] = 'refresh', [ 'control-r' ] = 'refresh',
} }
page = UI.Page { page = UI.Page {
backgroundColor = color.panelColor,
menuBar = UI.MenuBar { menuBar = UI.MenuBar {
transitionHint = 'slideLeft', transitionHint = 'slideLeft',
buttons = { buttons = {
@@ -136,24 +132,28 @@ page = UI.Page {
{ text = 'Edit', dropdown = { { text = 'Edit', dropdown = {
{ text = 'Cut ^x', event = 'menu_action', action = 'cut' }, { text = 'Cut ^x', event = 'menu_action', action = 'cut' },
{ text = 'Copy ^c', event = 'menu_action', action = 'copy' }, { text = 'Copy ^c', event = 'menu_action', action = 'copy' },
{ text = 'Paste ^V', event = 'paste_internal' }, { text = 'Paste ^V', event = 'menu_action', action = 'paste_internal' },
{ spacer = true }, { spacer = true },
{ text = 'Find... ^f', event = 'menu_action', action = 'find_prompt', noFocus = true }, { text = 'Find... ^f', event = 'menu_action', action = 'find_prompt', noFocus = true },
{ text = 'Find Next ^n', event = 'menu_action', action = 'find_next' }, { text = 'Find Next ^n', event = 'menu_action', action = 'find_next' },
{ spacer = true }, { spacer = true },
{ text = 'Go to line... ^g', event = 'menu_action', action = 'goto_line', noFocus = true }, { text = 'Go to line... ^g', event = 'menu_action', action = 'goto_line', noFocus = true },
{ text = 'Mark all ^a', event = 'menu_action', action = 'mark_all' }, { text = 'Mark all ^a', event = 'menu_action', action = 'mark_all' },
} }, } },
}, },
status = UI.Text {
textColor = color.statusColor,
x = -11, width = 10,
align = 'right',
},
}, },
gotoLine = UI.SlideOut { gotoLine = UI.SlideOut {
x = -15, height = 1, y = -2, x = -15, height = 1, y = -2,
noFill = true, noFill = true,
close = UI.Button { close = UI.Button {
x = -1, x = -1,
backgroundColor = colors.cyan, backgroundColor = color.panelColor,
backgroundFocusColor = colors.cyan, backgroundFocusColor = color.panelColor,
text = 'x', text = 'x',
event = 'slide_hide', event = 'slide_hide',
noPadding = true, noPadding = true,
@@ -197,8 +197,8 @@ page = UI.Page {
noFill = true, noFill = true,
close = UI.Button { close = UI.Button {
x = -1, x = -1,
backgroundColor = colors.cyan, backgroundColor = color.panelColor,
backgroundFocusColor = colors.cyan, backgroundFocusColor = color.panelColor,
text = 'x', text = 'x',
event = 'slide_hide', event = 'slide_hide',
noPadding = true, noPadding = true,
@@ -247,8 +247,8 @@ page = UI.Page {
noFill = true, noFill = true,
close = UI.Button { close = UI.Button {
x = -1, x = -1,
backgroundColor = colors.cyan, backgroundColor = color.panelColor,
backgroundFocusColor = colors.cyan, backgroundFocusColor = color.panelColor,
text = 'x', text = 'x',
event = 'slide_hide', event = 'slide_hide',
noPadding = true, noPadding = true,
@@ -296,8 +296,8 @@ page = UI.Page {
noFill = true, noFill = true,
close = UI.Button { close = UI.Button {
x = -1, x = -1,
backgroundColor = colors.cyan, backgroundColor = color.panelColor,
backgroundFocusColor = colors.cyan, backgroundFocusColor = color.panelColor,
text = 'x', text = 'x',
event = 'slide_hide', event = 'slide_hide',
noPadding = true, noPadding = true,
@@ -309,19 +309,19 @@ page = UI.Page {
save = UI.Button { save = UI.Button {
x = 7, x = 7,
text = 'Yes', text = 'Yes',
backgroundColor = colors.cyan, backgroundColor = color.panelColor,
event = 'save_yes', event = 'save_yes',
}, },
quit = UI.Button { quit = UI.Button {
x = 13, x = 13,
text = 'No', text = 'No',
backgroundColor = colors.cyan, backgroundColor = color.panelColor,
event = 'save_no', event = 'save_no',
}, },
cancel = UI.Button { cancel = UI.Button {
x = 18, x = 18,
text = 'Cancel', text = 'Cancel',
backgroundColor = colors.cyan, backgroundColor = color.panelColor,
event = 'save_cancel', event = 'save_cancel',
}, },
disable = function(self) disable = function(self)
@@ -346,7 +346,7 @@ page = UI.Page {
end, end,
}, },
editor = UI.Window { editor = UI.Window {
y = 2, ey = -2, y = 2,
backgroundColor = colors.black, backgroundColor = colors.black,
transitionHint = 'slideRight', transitionHint = 'slideRight',
focus = function(self) focus = function(self)
@@ -402,25 +402,13 @@ page = UI.Page {
end end
end, end,
}, },
statusBar = UI.StatusBar { notification = UI.Notification { },
transitionHint = 'slideLeft',
backgroundColor = colors.gray,
columns = {
{ key = 'general' },
{ key = 'pos', width = 6, fg = colors.orange },
},
},
enable = function(self) enable = function(self)
UI.Page.enable(self) UI.Page.enable(self)
self:setFocus(page.editor) self:setFocus(page.editor)
end, end,
eventHandler = function(self, event) eventHandler = function(self, event)
if event.type == 'paste_internal' then if event.type == 'menu_action' then
self:setFocus(page.editor)
os.queueEvent('clipboard_paste')
return true
elseif event.type == 'menu_action' then
actions.process(event.element.action) actions.process(event.element.action)
if not event.element.noFocus then -- hacky if not event.element.noFocus then -- hacky
self:setFocus(self.editor) self:setFocus(self.editor)
@@ -431,15 +419,6 @@ page = UI.Page {
end, end,
} }
local messages = {
wrapped = 'search hit BOTTOM, continuing at TOP',
}
if w < 32 then
messages = {
wrapped = 'search wrapped',
}
end
local function getFileInfo(path) local function getFileInfo(path)
local abspath = shell.resolve(path) local abspath = shell.resolve(path)
@@ -455,22 +434,16 @@ local function getFileInfo(path)
else else
fi.isReadOnly = fs.isReadOnly(fi.abspath) fi.isReadOnly = fs.isReadOnly(fi.abspath)
end end
_G._p = fi
return fi return fi
end end
local function setStatus(pattern, ...) local function setStatus(pattern, ...)
sStatus = string.format(pattern, ...) page.notification:info(string.format(pattern, ...))
page.statusBar.textColor = colors.white
page.statusBar:setValue('general', sStatus)
page.statusBar:draw()
end end
local function setError(pattern, ...) local function setError(pattern, ...)
sStatus = string.format(pattern, ...) page.notification:error(string.format(pattern, ...))
page.statusBar.textColor = color.highlightColor
page.statusBar:setValue('general', sStatus)
page.statusBar:draw()
end end
local function load(path) local function load(path)
@@ -492,9 +465,6 @@ local function load(path)
end end
local name = fileInfo.path local name = fileInfo.path
if w < 32 then
name = fs.getName(fileInfo.path)
end
if fileInfo.isNew then if fileInfo.isNew then
if not fileInfo.dirExists then if not fileInfo.dirExists then
setStatus('"%s" [New DIRECTORY]', name) setStatus('"%s" [New DIRECTORY]', name)
@@ -578,12 +548,7 @@ local function writeHighlighted(sLine, ny, dy)
local function tryWrite(line, regex, fgcolor) local function tryWrite(line, regex, fgcolor)
local match = line:match(regex) local match = line:match(regex)
if match then if match then
local fg local fg = type(fgcolor) == "string" and fgcolor or fgcolor(match)
if type(fgcolor) == "string" then
fg = fgcolor
else
fg = fgcolor(match)
end
buffer.text = buffer.text .. match buffer.text = buffer.text .. match
buffer.fg = buffer.fg .. string.rep(fg, #match) buffer.fg = buffer.fg .. string.rep(fg, #match)
return line:sub(#match + 1) return line:sub(#match + 1)
@@ -611,10 +576,7 @@ local function writeHighlighted(sLine, ny, dy)
buffer.text = buffer.text .. '\183' buffer.text = buffer.text .. '\183'
if mark.active and ny >= mark.y and ny <= mark.ey then if mark.active and ny >= mark.y and ny <= mark.ey then
local sx = 1 local sx = ny == mark.y and mark.x or 1
if ny == mark.y then
sx = mark.x
end
local ex = #buffer.text local ex = #buffer.text
if ny == mark.ey then if ny == mark.ey then
ex = mark.ex ex = mark.ex
@@ -646,35 +608,15 @@ local function redraw()
end end
end end
-- Draw status local modifiedIndicator = undo.chain[#undo.chain] == lastSave and '' or '*'
if #sStatus == 0 then page.menuBar.status.value = string.format(' %d:%d%s', y, x, modifiedIndicator)
page.statusBar:setValue('general', '') page.menuBar.status:draw()
page.statusBar:draw()
end
if not (w < 32 and #sStatus > 0) then
local modifiedIndicator = ''
if undo.chain[#undo.chain] ~= lastSave then
modifiedIndicator = '*'
end
local str = string.format(' %d:%d%s',
y, x, modifiedIndicator)
page.statusBar:setValue('pos', str)
page.statusBar.columns[2].width = #str
page.statusBar:adjustWidth()
page.statusBar:draw()
end
if page.editor.focused then if page.editor.focused then
page.editor:setCursorPos(x - scrollX, y - scrollY) page.editor:setCursorPos(x - scrollX, y - scrollY)
end end
dirty.y, dirty.ey = 0, 0 dirty.y, dirty.ey = 0, 0
if #sStatus > 0 then
sStatus = ''
end
end end
local function nextWord(line, cx) local function nextWord(line, cx)
@@ -703,7 +645,7 @@ actions = {
addUndo = function(entry) addUndo = function(entry)
local last = undo.chain[#undo.chain] local last = undo.chain[#undo.chain]
if last and last.action == entry.action and not last.saved then if last and last.action == entry.action then
if last.action == 'deleteText' then if last.action == 'deleteText' then
if last.args[3] == entry.args[1] and if last.args[3] == entry.args[1] and
last.args[4] == entry.args[2] then last.args[4] == entry.args[2] then
@@ -790,10 +732,10 @@ actions = {
if ny > nLines then if ny > nLines then
ny = ny - nLines ny = ny - nLines
end end
local nx = tLines[ny]:lower():find(pattern, sx) local nx = tLines[ny]:lower():find(pattern, sx, true)
if nx then if nx then
if ny < y or ny == y and nx <= x then if ny < y or ny == y and nx <= x then
setStatus(messages.wrapped) setStatus('search hit BOTTOM, continuing at TOP')
end end
actions.go_to(nx, ny) actions.go_to(nx, ny)
actions.mark_to(nx + #pattern, ny) actions.mark_to(nx + #pattern, ny)
@@ -1305,6 +1247,10 @@ actions = {
end end
end, end,
paste_internal = function()
os.queueEvent('clipboard_paste')
end,
go_to = function(cx, cy) go_to = function(cx, cy)
y = math.min(math.max(cy, 1), #tLines) y = math.min(math.max(cy, 1), #tLines)
x = math.min(math.max(cx, 1), #tLines[y] + 1) x = math.min(math.max(cx, 1), #tLines[y] + 1)