Skip to content

Commit 8adec63

Browse files
committed
➕ Add platformdirs
1 parent 226d160 commit 8adec63

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

lua/prompt/style.lua

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---prompt style.
22
local os = require "os"
3-
local table = require "table"
4-
local lfs = require"lfs"
3+
4+
local lfs = require "lfs"
5+
local uv = require "platformdirs.uv"
56
local warna = require "warna"
67
warna.options.level = 3
78
local ansicolors = warna.format
89
local prompt = require "prompt"
9-
---@diagnostic disable: deprecated
10-
if table.unpack == nil then table.unpack = unpack end
1110

1211
---wakatime
1312
---@param cmd string | nil
@@ -121,15 +120,15 @@ end
121120
---get os
122121
---@return string
123122
local function get_os()
124-
if os.getenv("PREFIX") == "/data/data/com.termux/files/usr" then
123+
if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system" then
125124
return "android"
126125
end
127-
local binary_format = package.cpath:match('([^.]+);?$')
128-
if binary_format == "so" then
126+
local sysname = uv.os_uname().sysname:lower()
127+
if sysname:find('linux') or sysname:find('unix') then
129128
return get_distribution()
130-
elseif binary_format == "dll" then
129+
elseif sysname:find('windows') or sysname:find('mingw') then
131130
return "windows"
132-
elseif binary_format == "dylib" then
131+
elseif sysname:find('macos') then
133132
return "macos"
134133
end
135134
return "unknown"
@@ -219,11 +218,11 @@ end
219218
local function generate_ps1(char, sections)
220219
char = char or ""
221220
sections = sections or {
222-
---@diagnostic disable: missing-parameter
223-
{ "", "", wakatime },
224-
{ "black", "yellow", get_icon() }, { "blue", "black", get_version() },
225-
{ "white", "blue", get_cwd }, { "black", "white", get_time }
226-
}
221+
---@diagnostic disable: missing-parameter
222+
{ "", "", wakatime },
223+
{ "black", "yellow", get_icon() }, { "blue", "black", get_version() },
224+
{ "white", "blue", get_cwd }, { "black", "white", get_time }
225+
}
227226
local sep = ""
228227
local format = " %s "
229228
return function()
@@ -237,7 +236,9 @@ local function generate_ps1(char, sections)
237236
sep = v
238237
end
239238
else
240-
local fg, bg, text = table.unpack(v)
239+
local fg = v[1]
240+
local bg = v[2]
241+
local text = v[3]
241242
if type(text) == "function" then text = text() end
242243
if text ~= "" then
243244
text = format:format(text)

lua/prompt/utils.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---prompt utils.
22
local argparse = require "argparse"
3+
local PlatformDirs = require "platformdirs".PlatformDirs
34
local prompt = require "prompt"
45
local style = require "prompt.style"
56
local M = {}
@@ -223,8 +224,7 @@ end
223224
---source configs
224225
---@param configs string[] | nil
225226
function M.source_configs(configs)
226-
configs = configs or { os.getenv('HOME') .. '/.luaprc.lua',
227-
os.getenv('HOME') .. '/.config/luaprc.lua' }
227+
configs = configs or { PlatformDirs { appname = "luaprc.lua" }:user_config_dir() }
228228
for _, name in ipairs(configs) do
229229
local f = io.open(name, "r")
230230
if f ~= nil then

template.rockspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies = {
2020
"lua >= 5.1",
2121
"warna",
2222
"argparse",
23+
"platformdirs",
2324
"luafilesystem",
2425
"luaprompt"
2526
}

0 commit comments

Comments
 (0)