-- powerline glyphs for easy cut'n'paste:   
local group_sep = lash.root:has_glyph("") and " " or "> "
local collapse_sym = lash.root:has_glyph("▲") and "▲" or "[-]"
local expand_sym = lash.root:has_glyph("▼") and "▼" or "[+]"
local selected_sym = lash.root:has_glyph("►") and "►" or ">"

local fmt_sep = {fc = tui.colors.label, bc = tui.colors.text}
local fmt_data = {fc = tui.colors.inactive, bc = tui.colors.text}

-- hints match their config key here
local hintbl = {
	autoexpand_latest = "The latest job always starts as 'view expanded'",
	autocontract_last = "The previous job will contract when a new one is spawned",
	autosuggest = "Toggle completion without manually pressing TAB",
	allow_state = "Permit external WM to control state load/store",
	debug = "Write parser debug information to 'view monitor'",
	hex_mode = "Builtin hex editor default presentation (hex, hex_detail, hex_detail_meta)",
	content_offset = "Number of columns of padding between line column and content",
	job_pad = "Number of empty rows between job views",
	job_bar_pad = "Pad header to end of job column",
	collapsed_rows = "Number of visible rows for a contracted job",
	autoclear_empty = "Automatically forget #jobid for completed silent jobs",
	show_line_number = "Set view linenumber for new jobs",
	autokill_quiet_bad = "Timeout for silent jobs that failed with EXIT_FAILURE",
	plumber = "Binary used for external open",
	main_column_width = "Number of columns for main jobs",
	min_column_width = "Number of columns for side jobs",
	multicolumn = "Allow splitting into multiple columns",
	open_spawn_default = "Suggested open mode (embed, split, join-r, tab, swallow)",
	clipboard_job = "Create a new job that absorbs all pasted input",
	sh_runner = "Program to invoke for subshell commands",
	sh_user_prefix = "Prefix to run shell commands as a different user",
	default_job_view = "Default view action for new jobs",
	detach_keep = "Set to reattach detached job on window destruction",
	open_embed_collapsed_rows = "Number of rows for downscaled contract open embed",
	["=reload"] = "Re-parse and apply config.lua",
	accessibility = "Probe display server for accessibility needs at startup",
	single_job = "Only show a single job at any time",
	a11y_limit = "Number of 25Hz ticks between queued messages",
	process_lines = "Number of lines to process in each update",
	shell_job_deferred = "Defer showing job data until exited",
	shell_job_linecount = 10000, "Maximum number of lines to process per pass",
	mouse_mode = string.format(
		"(Advanced) override mouse mode flag (%d, %d)", tui.flags.mouse, tui.flags.mouse_full),
}
 -- tui.flags.mouse_full blocks meta+drag-select
-- simpler toggles for dynamically controlling presentation
return
{
	hint = hintbl,
	autoexpand_latest = true,
	autocontract_last = false,
	autosuggest = true,
	debug = false,
	hex_mode = "hex_detail_meta",

	content_offset = 1,
	job_pad        = 1,
	collapsed_rows = 4,
	collapse_symbol = collapse_sym,
	expand_symbol = expand_sym,
	autoclear_empty = true,
	show_line_number = true,
	autokill_quiet_bad = 100,
	detach_keep = false,

	term_plumber = "/usr/bin/nvim",
	plumber = "/usr/bin/afsrv_decode",

	default_job_view = "crop",
	shell_job_deferred = true,
	shell_job_linecount = 10000,

-- probe for accessibility segment at startup, adds 10-50ms time so disable if
-- you don't need or want to test for it
	accessibility = true,

-- replace these options if an accessibility window appears
	accessibility_overrides = {
		single_job = true,
		autosuggest = false
	},

	a11y_limit = 20,

	main_column_width = 80,
	min_column_width = 40,
	multicolumn = false,
	single_job = false,

	open_spawn_default = "swallow",
	open_embed_collapsed_rows = 4,
--	open_external = "/usr/bin/nvim", -- set to skip the internal viewer

	process_lines = 100,
	clipboard_job = true,
	mouse_mode = tui.flags.mouse,
	allow_state = true,

-- sh-runner is configurable, will be rebuilt into argv through string.split(" ")
-- this means that we can have a privileged root default, but default to run
-- as a targetted user.
	sh_runner = "/bin/sh sh -c",
	sh_user_prefix = "/bin/doas -u",

-- subtables are ignored for the config builtin
--
-- possible job-bar meta entries (cat9/base/jobmeta.lua):
--  $pid_or_exit, $id, $data, $hdr_data, $memory_use, $dir, $full, $short
--
-- the action subtable matches
--
	job_bar_collapsed =
	{
		group_sep = group_sep,
		{expand_sym},
		{"#", "$id", group_sep, group_sep, "$pid_or_exit", group_sep, "$memory_use"},
		{"$short"},
	},

	job_bar_selected =
	{
		group_sep = group_sep,
		{selected_sym, "#", "$id", group_sep, "$pid_or_exit", group_sep, "$memory_use"},
		{"$short"},
		{function(cat9, job) return job["repeat"] and "repeat" or ""; end},
		{function(cat9, job)
			if job.pid then
				return job.deferred and "undefer" or "defer"
			else
				return ""
			end
		end
		},
		{"X"},
		m1 = {
			[3] = "repeat #csel flush",
			[4] = "view #csel defer",
			[5] = "forget #csel"
		}
	},

	job_bar_expanded =
	{
		group_sep = group_sep,
		{ collapse_sym, "#", "$id", group_sep, "$pid_or_exit", group_sep, "$memory_use"},
		{"$view"},
		{"$full_or_short"},
		prefix = {fmt_sep, "[", fmt_data},
		suffix = {fmt_sep, "]", fmt_data}
	},

	job_bar_pad = true,

-- similar to job_bar but no click-groups so only one level of tables
-- possible specials defined in base/promptmeta.lua
	prompt_focus =
	{
		"$chord_state",
		"$begin",
		function() return os.date("%H:%M:%S") end,
		"$begin",
		"$battery_charging $battery_pct % $battery_power W",
		"$begin",
		"$jobs",
		"$begin",
		"$builtin_name",
		"$builtin_status",
		"$dynamic", -- insertion point for any builtins that attach itself
		"$end", -- force stop any remaining group
		" > ",
		fmt_data,
		"$lastdir",
		"# ",
		prefix = {fmt_sep, "[", fmt_data},
		suffix = {fmt_sep, "]", fmt_data}
	},

	prompt =
	{
		"$begin",
		"$lastdir",
		prefix = {fmt_sep, "<", fmt_data},
		suffix = {fmt_sep, ">", fmt_data}
	},

	readline =
	{
		cancellable   = false,  -- cancel removes readline until we starts typing
		forward_meta  = false,  -- don't need meta-keys, use default rl behaviour
		forward_paste = true,   -- ignore builtin paste behaviour
		forward_mouse = true,   -- needed for clicking outside the readline area
		whitespace_expand = false,
		linefeed_expand = false,
	},

	styles =
	{
		line_number = {fc = tui.colors.label, bc = tui.colors.label},
		data = {fc = tui.colors.text, bc = tui.colors.text},
		data_highlight = {fc = tui.colors.alert, bc = tui.colors.alert},
		error_line = {fc = tui.colors.ref_red, bc = tui.colors.text},
		ok_line = {fc = tui.colors.ref_green, bc = tui.colors.text},
		column_header = {border_down = true, fc = tui.colors.ui, bc = tui.colors.label},
		match_set = {
			{fc = tui.colors.ref_red, bc = tui.colors.text},
			{fc = tui.colors.ref_green, bc = tui.colors.text},
			{fc = tui.colors.ref_yellow, bc = tui.colors.text},
			{fc = tui.colors.ref_blue, bc = tui.colors.text},
			{fc = tui.colors.ref_magenta, bc = tui.colors.text},
			{fc = tui.colors.ref_cyan, bc = tui.colors.text}
		}
	},

	edit =
	{
-- bytes to limit on-enter backup
		snapshot_size = 1024 * 1024 * 2,

-- color override for visual selection
		select = {
			bc = tui.colors.ref_red,
			br = 64,
			bg = 0,
			bb = 0,
			border_down = true
		},
		bar = {
			input = tui.colors.ref_green,
			command = tui.colors.highlight,
			visual = tui.colors.ref_blue,
			append = tui.colors.ref_green,
			replace = tui.colors.ref_red
		}
	},

	glob =
	{
		dir_argv = {"/usr/bin/env", "/usr/bin/env", "find", "$path", "-maxdepth", "1", "-type", "d"},
		file_argv = {"/usr/bin/env", "/usr/bin/env", "find", "$path", "-maxdepth", "1"}
	},

-- each set of builtins (including the default) gets a subtable in here that
-- is populated when loading the set itself, and overlayed by config/setname.lua
	builtins = {
	}
}
