more defaults
This commit is contained in:
parent
8891f371a8
commit
af81516211
18
README.md
18
README.md
|
@ -16,7 +16,7 @@ Use `layotu = layout_machi.layout.create()` to instantiate the layout.
|
|||
|
||||
## Use the editor
|
||||
|
||||
Call `editor = layout_machi.editor.create(data)` to create an editor that can either
|
||||
Call `editor = layout_machi.editor.create()` to create an editor that can either
|
||||
|
||||
- Interactively edit layout by calling `editor.start_interactive()`
|
||||
- Set the layout with batched commands by calling `editor.set_by_cmd(cmd)`, where cmd is a string
|
||||
|
@ -25,9 +25,8 @@ Call `editor = layout_machi.editor.create(data)` to create an editor that can ei
|
|||
|
||||
### The layout editing command
|
||||
|
||||
The editor starts with the open area of the entire workarea, taking command to split the current area into multiple sub-areas, then editing each of them.
|
||||
The editor is keyboard driven, accepting a number of command keys.
|
||||
Before each command, you can optionally provide at most 2 digits for parameters (A, B) of the command.
|
||||
The editing starts with the open area of the entire workarea, takes commands to split the current area into multiple sub-areas, then recursively edits each of them.
|
||||
The editor is keyboard driven, each command is a key with at most 2 digits as parameters (A, B) before the command.
|
||||
Undefined parameters are (mostly) treated as 1.
|
||||
|
||||
1. `Up`/`Down`: restore to the history command sequence
|
||||
|
@ -92,15 +91,8 @@ Tada!
|
|||
|
||||
### Persistent history
|
||||
|
||||
If you want all command persisted, you need to specify the path of the history file in the editor data.
|
||||
The persisted history can be restored by `layout_machi.editor.restore_data(...)`. For example,
|
||||
|
||||
```
|
||||
machi_editor_data = layout_machi.editor.restore_data({ history_file = ".machi-layout", history_save_max = 10 })
|
||||
```
|
||||
|
||||
The last `history_save_max` commands are persisted.
|
||||
|
||||
By default, the last 100 command sequences is stored in `~/.machi_history`.
|
||||
To change that, please refer to `editor.lua`. (XXX more documents)
|
||||
|
||||
## Other functions
|
||||
|
||||
|
|
62
editor.lua
62
editor.lua
|
@ -21,12 +21,12 @@ local open_color = "#00000080"
|
|||
local closed_color = "#00000080"
|
||||
local init_max_depth = 2
|
||||
|
||||
function is_tiling(c)
|
||||
local function is_tiling(c)
|
||||
return
|
||||
not (c.tomb_floating or c.floating or c.maximized_horizontal or c.maximized_vertical or c.maximized or c.fullscreen)
|
||||
end
|
||||
|
||||
function set_tiling(c)
|
||||
local function set_tiling(c)
|
||||
c.floating = false
|
||||
c.maximized = false
|
||||
c.maximized_vertical = false
|
||||
|
@ -34,15 +34,15 @@ function set_tiling(c)
|
|||
c.fullscreen = false
|
||||
end
|
||||
|
||||
function min(a, b)
|
||||
local function min(a, b)
|
||||
if a < b then return a else return b end
|
||||
end
|
||||
|
||||
function max(a, b)
|
||||
local function max(a, b)
|
||||
if a < b then return b else return a end
|
||||
end
|
||||
|
||||
function set_region(c, r)
|
||||
local function set_region(c, r)
|
||||
c.floating = false
|
||||
c.maximized = false
|
||||
c.fullscreen = false
|
||||
|
@ -51,7 +51,7 @@ function set_region(c, r)
|
|||
end
|
||||
|
||||
-- find the best region for the area
|
||||
function fit_region(c, regions)
|
||||
local function fit_region(c, regions)
|
||||
local choice = 1
|
||||
local choice_value = nil
|
||||
local c_area = c.width * c.height
|
||||
|
@ -77,7 +77,7 @@ function fit_region(c, regions)
|
|||
return choice
|
||||
end
|
||||
|
||||
function cycle_region(c)
|
||||
local function cycle_region(c)
|
||||
layout = api.layout.get(c.screen)
|
||||
regions = layout.get_regions and layout.get_regions()
|
||||
if type(regions) ~= "table" or #regions < 1 then
|
||||
|
@ -97,17 +97,42 @@ function cycle_region(c)
|
|||
api.layout.arrange(c.screen)
|
||||
end
|
||||
|
||||
function _area_tostring(wa)
|
||||
local function _area_tostring(wa)
|
||||
return "{x:" .. tostring(wa.x) .. ",y:" .. tostring(wa.y) .. ",w:" .. tostring(wa.width) .. ",h:" .. tostring(wa.height) .. "}"
|
||||
end
|
||||
|
||||
function shrink_area_with_gap(a, gap)
|
||||
local function shrink_area_with_gap(a, gap)
|
||||
return { x = a.x + (a.bl and 0 or gap / 2), y = a.y + (a.bu and 0 or gap / 2),
|
||||
width = a.width - (a.bl and 0 or gap / 2) - (a.br and 0 or gap / 2),
|
||||
height = a.height - (a.bu and 0 or gap / 2) - (a.bd and 0 or gap / 2) }
|
||||
end
|
||||
|
||||
function create(data)
|
||||
local function restore_data(data)
|
||||
if data.history_file then
|
||||
local file, err = io.open(data.history_file, "r")
|
||||
if err then
|
||||
print("cannot read history from " .. data.history_file)
|
||||
else
|
||||
data.cmds = {}
|
||||
for line in file:lines() do
|
||||
print("restore cmd " .. line)
|
||||
data.cmds[#data.cmds + 1] = line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
local function create(data)
|
||||
if data == nil then
|
||||
data = restore_data({
|
||||
history_file = ".machi_history",
|
||||
history_save_max = 100
|
||||
gap = beautiful.useless_gap
|
||||
})
|
||||
end
|
||||
|
||||
local gap = data.gap or 0
|
||||
|
||||
local closed_areas
|
||||
|
@ -610,23 +635,6 @@ function create(data)
|
|||
}
|
||||
end
|
||||
|
||||
function restore_data(data)
|
||||
if data.history_file then
|
||||
local file, err = io.open(data.history_file, "r")
|
||||
if err then
|
||||
print("cannot read history from " .. data.history_file)
|
||||
else
|
||||
data.cmds = {}
|
||||
for line in file:lines() do
|
||||
print("restore cmd " .. line)
|
||||
data.cmds[#data.cmds + 1] = line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
return
|
||||
{
|
||||
set_region = set_region,
|
||||
|
|
Loading…
Reference in New Issue