Skip to content

Commit c607f5c

Browse files
committed
✨ Add name
1 parent f5a3e15 commit c607f5c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

bin/neomuttp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local ext = string.match(package.cpath, '([^.]+)[;|$]')
99
package.cpath = package.cpath .. ";/usr/lib/lua/" .. version .. "/?." .. ext
1010

1111
local prompt = require "prompt"
12-
prompt.name = 'texlua'
12+
prompt.name = 'neomutt'
1313
prompt.prompts = { '> ', '>> ' }
1414
prompt.colorize = true
1515
prompt.history = os.getenv('HOME') .. '/.lua_history'

prompt-style.lua

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ local string = require "string"
44
local table = require "table"
55
local lfs = require "lfs"
66
local ansicolors = require "ansicolors"
7+
local prompt = require "prompt"
8+
---@diagnostic disable: deprecated
79
if table.unpack == nil then table.unpack = unpack end
810

911
---get distribution
@@ -52,12 +54,17 @@ local function get_icon()
5254
end
5355

5456
---get version
57+
---@param name string
5558
---@param logo string
59+
---@param format string
5660
---@return string
57-
local function get_version(logo)
58-
logo = logo or ""
61+
local function get_version(name, logo, format)
62+
name = name or prompt.name
63+
logo = logo or ""
64+
format = format or " %s "
65+
name = string.format(format, name)
5966
local version = string.gsub(_VERSION, ".*%s+", "")
60-
return logo .. version
67+
return logo .. name .. version
6168
end
6269

6370
---get time
@@ -79,18 +86,21 @@ local function get_cwd()
7986
end
8087

8188
---generate ps1.
89+
-- `name` is for `get_version()`
8290
-- `sections` is an array whose element is like `{ "white", "blue", get_cwd }`
8391
-- and its order determine the order of prompt sections.
8492
-- `sep` is separator. `char` is the last character like `> `
8593
-- `format` determine the space and by default is ' %s '.
94+
---@param name string
8695
---@param sections {1: integer, 2: integar, 3: string | function(): string}[]
8796
---@param sep string
8897
---@param char string
8998
---@param format string
9099
---@return function(): string
91-
local function generate_ps1(sections, sep, char, format)
100+
local function generate_ps1(name, sections, sep, char, format)
101+
name = name or prompt.name
92102
sections = sections or {
93-
{"black", "yellow", get_icon()}, {"blue", "black", get_version()},
103+
{"black", "yellow", get_icon()}, {"blue", "black", get_version(name)},
94104
{"white", "blue", get_cwd}, {"black", "white", get_time}
95105
}
96106
sep = sep or ""

0 commit comments

Comments
 (0)