From ba6b082ed404f37cd315be11182dde3ac345a6c0 Mon Sep 17 00:00:00 2001 From: xeroarch Date: Wed, 2 Oct 2024 13:12:57 -0400 Subject: [PATCH 01/10] putting xeroarch logo in askii --- src/logo/ascii/ascii-art.txt | 45 ++++++++++++++++++++++++++++++++++++ src/logo/ascii/xeroarch.txt | 45 ++++++++++++++++++++++++++++++++++++ src/logo/builtin.c | 10 ++++++++ 3 files changed, 100 insertions(+) create mode 100755 src/logo/ascii/ascii-art.txt create mode 100644 src/logo/ascii/xeroarch.txt diff --git a/src/logo/ascii/ascii-art.txt b/src/logo/ascii/ascii-art.txt new file mode 100755 index 0000000000..d72aeac27b --- /dev/null +++ b/src/logo/ascii/ascii-art.txt @@ -0,0 +1,45 @@ + + @@%%@@ + @%%%%%%@ + @%%%%%%%%%@ + @%%%%%%%%%%@ + @@%%%%%*=%%%%%%@ + @@%%%%%*-:=%%%%%%@ + @%%%%%%*::::=%%%%%%@ + @%%%%%%*::::::=%%%%%%@ + @%%%%%%+::::::::=%%%%%%@ + @%%%%%%+::::::::::-%%%%%%@ + @%%%%%%=::::::::::::-%%%%%%@ + @%%%%%%=:::::::::::::::%%%%%%@ + @%%%%%%=::::::::::::::::-%%%%%%@ + @%%%%%%=:::::::::::::::::::#%%%%%@ + @%%%%%%=::::::::::::::::::::-#%%%%%@ + @%%%%%%-::::::::::**:::::::::::*%%%%%@@ + @%%%%%%-::::::::::=%%=:::::::::::#%%%%%@ + @%%%%%%%-:::::::::::*%%%:::::::::::=%%%%%%%@ + @@%%%%%%-:::::::::::=%%%%=::::::::::-%%%%%%%%@ + @%%%%%%#:::::::::::::*%%%%#::::::::::+%%%%%%%%%@ + @%%%%%%%=-::::::::::::*%%%%*:::::::::-%%%%%%%%%%%@ + @%%%%%%%%%%%*:::::::::::%%%%=::::::::-%%%%%%%%%%%%%@ + @%%%%%%%%%%%%%%%*-:::::::%%%%-:::::::*%%%%%%%%%%%%%%%@ + @%%%%%%*====*%%%%%%%+:-+#%%%%%%%*-:=*%%%%%%%%%%%%%%%%%%@ + @%%%%%%*========*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @%%%%%%*============*%%%%%%%%%%%%%%%%%%%+-::::::::::=%%%%%%@ + @%%%%%%*==============%%%%%%%%%%%%%%%%%%-:::::::::::::-%%%%%%@ + @%%%%%%+===============%%%%%%%%%%%%%%%%%%=::::::::::::::-%%%%%%@ + @%%%%%%+================%%%%%%%%%%%%%%%%%%=:::::::::::::::-#%%%%%@@ + @%%%%%%+=================#%%%%%%%%%%%%%%%%%-::::::::::::::::-#%%%%%@ + %%%%%%%===============+%%%%%%%%%%%%%%%%%%%%%%%%=:::::::::::::::#%%%%%%@ + @%%%%%%=============#%%%%%%%%*%%%%%%%%%%%%*%%%%%%%%#-::::::::::::#%%%%%%@ + @%%%%%%%============#%%%%%%%#+====*#%%%%#*=:::-*%%%%%%%#=:::::::::::*%%%%%%@ + @%%%%%%%===========#%%%%%%*+=========%%%%=::::::::-*##%%%%#=::::::::::*%%%%%%@ + @%%%%%%%==============================%%%%=:::::::::::::::::::::::::::::+%%%%%%@ + @%%%%%%%===============================%%%%=::::::::::::::::::::::::::::::+%%%%%%@ + @%%%%%%#================================%%%%%-::::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%#=================================*%%%%#-::::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%#==================================+%%%%%%=::::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%#====================================#%%%%%%%*-::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@ + diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt new file mode 100644 index 0000000000..67eb655d03 --- /dev/null +++ b/src/logo/ascii/xeroarch.txt @@ -0,0 +1,45 @@ + + @@%%@@ + @%%%%%%@ + @%%%%%%%%%@ + @%%%%%%%%%%@ + @@%%%%%*=%%%%%%@ + @@%%%%%*-:=%%%%%%@ + @%%%%%%*::::=%%%%%%@ + @%%%%%%*::::::=%%%%%%@ + @%%%%%%+::::::::=%%%%%%@ + @%%%%%%+::::::::::-%%%%%%@ + @%%%%%%=::::::::::::-%%%%%%@ + @%%%%%%=:::::::::::::::%%%%%%@ + @%%%%%%=::::::::::::::::-%%%%%%@ + @%%%%%%=:::::::::::::::::::#%%%%%@ + @%%%%%%=::::::::::::::::::::-#%%%%%@ + @%%%%%%-::::::::::**:::::::::::*%%%%%@@ + @%%%%%%-::::::::::=%%=:::::::::::#%%%%%@ + @%%%%%%%-:::::::::::*%%%:::::::::::=%%%%%%%@ + @@%%%%%%-:::::::::::=%%%%=::::::::::-%%%%%%%%@ + @%%%%%%#:::::::::::::*%%%%#::::::::::+%%%%%%%%%@ + @%%%%%%%=-::::::::::::*%%%%*:::::::::-%%%%%%%%%%%@ + @%%%%%%%%%%%*:::::::::::%%%%=::::::::-%%%%%%%%%%%%%@ + @%%%%%%%%%%%%%%%*-:::::::%%%%-:::::::*%%%%%%%%%%%%%%%@ + @%%%%%%*====*%%%%%%%+:-+#%%%%%%%*-:=*%%%%%%%%%%%%%%%%%%@ + @%%%%%%*========*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @%%%%%%*============*%%%%%%%%%%%%%%%%%%%+-::::::::::=%%%%%%@ + @%%%%%%*==============%%%%%%%%%%%%%%%%%%-:::::::::::::-%%%%%%@ + @%%%%%%+===============%%%%%%%%%%%%%%%%%%=::::::::::::::-%%%%%%@ + @%%%%%%+================%%%%%%%%%%%%%%%%%%=:::::::::::::::-#%%%%%@@ + @%%%%%%+=================#%%%%%%%%%%%%%%%%%-::::::::::::::::-#%%%%%@ + %%%%%%%===============+%%%%%%%%%%%%%%%%%%%%%%%%=:::::::::::::::#%%%%%%@ + @%%%%%%=============#%%%%%%%%*%%%%%%%%%%%%*%%%%%%%%#-::::::::::::#%%%%%%@ + @%%%%%%%============#%%%%%%%#+====*#%%%%#*=:::-*%%%%%%%#=:::::::::::*%%%%%%@ + @%%%%%%%===========#%%%%%%*+=========%%%%=::::::::-*##%%%%#=::::::::::*%%%%%%@ + @%%%%%%%==============================%%%%=:::::::::::::::::::::::::::::+%%%%%%@ + @%%%%%%%===============================%%%%=::::::::::::::::::::::::::::::+%%%%%%@ + @%%%%%%#================================%%%%%-::::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%#=================================*%%%%#-::::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%#==================================+%%%%%%=::::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%#====================================#%%%%%%%*-::::::::::::::::::::::::::::=%%%%%%@ + @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@ + diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 62f8291cad..efb361355c 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -4785,6 +4785,16 @@ static const FFlogo X[] = { FF_COLOR_FG_CYAN, }, }, + //XeroArch + { + .names = {"XeroArch"}, + .lines = FASTFETCH_DATATEXT_LOGO_XEROARCH, + .colors = { + FF_COLOR_FG_256 "15", + FF_COLOR_FG_256 "14", + FF_COLOR_FG_256 "16", + } + }, //Xray_OS { .names = {"Xray_OS"}, From 634541a094fcb4aef2316b4f8748127d59ed3e95 Mon Sep 17 00:00:00 2001 From: xeroarch Date: Wed, 2 Oct 2024 14:06:26 -0400 Subject: [PATCH 02/10] updating logo --- src/logo/ascii/xeroarch.txt | 67 ++++++++++++------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 67eb655d03..1f79ffe8c9 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -1,45 +1,22 @@ - - @@%%@@ - @%%%%%%@ - @%%%%%%%%%@ - @%%%%%%%%%%@ - @@%%%%%*=%%%%%%@ - @@%%%%%*-:=%%%%%%@ - @%%%%%%*::::=%%%%%%@ - @%%%%%%*::::::=%%%%%%@ - @%%%%%%+::::::::=%%%%%%@ - @%%%%%%+::::::::::-%%%%%%@ - @%%%%%%=::::::::::::-%%%%%%@ - @%%%%%%=:::::::::::::::%%%%%%@ - @%%%%%%=::::::::::::::::-%%%%%%@ - @%%%%%%=:::::::::::::::::::#%%%%%@ - @%%%%%%=::::::::::::::::::::-#%%%%%@ - @%%%%%%-::::::::::**:::::::::::*%%%%%@@ - @%%%%%%-::::::::::=%%=:::::::::::#%%%%%@ - @%%%%%%%-:::::::::::*%%%:::::::::::=%%%%%%%@ - @@%%%%%%-:::::::::::=%%%%=::::::::::-%%%%%%%%@ - @%%%%%%#:::::::::::::*%%%%#::::::::::+%%%%%%%%%@ - @%%%%%%%=-::::::::::::*%%%%*:::::::::-%%%%%%%%%%%@ - @%%%%%%%%%%%*:::::::::::%%%%=::::::::-%%%%%%%%%%%%%@ - @%%%%%%%%%%%%%%%*-:::::::%%%%-:::::::*%%%%%%%%%%%%%%%@ - @%%%%%%*====*%%%%%%%+:-+#%%%%%%%*-:=*%%%%%%%%%%%%%%%%%%@ - @%%%%%%*========*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @%%%%%%*============*%%%%%%%%%%%%%%%%%%%+-::::::::::=%%%%%%@ - @%%%%%%*==============%%%%%%%%%%%%%%%%%%-:::::::::::::-%%%%%%@ - @%%%%%%+===============%%%%%%%%%%%%%%%%%%=::::::::::::::-%%%%%%@ - @%%%%%%+================%%%%%%%%%%%%%%%%%%=:::::::::::::::-#%%%%%@@ - @%%%%%%+=================#%%%%%%%%%%%%%%%%%-::::::::::::::::-#%%%%%@ - %%%%%%%===============+%%%%%%%%%%%%%%%%%%%%%%%%=:::::::::::::::#%%%%%%@ - @%%%%%%=============#%%%%%%%%*%%%%%%%%%%%%*%%%%%%%%#-::::::::::::#%%%%%%@ - @%%%%%%%============#%%%%%%%#+====*#%%%%#*=:::-*%%%%%%%#=:::::::::::*%%%%%%@ - @%%%%%%%===========#%%%%%%*+=========%%%%=::::::::-*##%%%%#=::::::::::*%%%%%%@ - @%%%%%%%==============================%%%%=:::::::::::::::::::::::::::::+%%%%%%@ - @%%%%%%%===============================%%%%=::::::::::::::::::::::::::::::+%%%%%%@ - @%%%%%%#================================%%%%%-::::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%#=================================*%%%%#-::::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%#==================================+%%%%%%=::::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%#====================================#%%%%%%%*-::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@ - + @@ + @%%%%@ + @%%%%%%@ + @%%%--#%%@ + @%%#----#%%@ + @%%#------*%%@ + @%%#--------*%%% + @%%*----------+%%@ + @%%%*-----+*-----+%%%@ + %%%+------%%------%%%%@ + @%%%#------=%%=----*%%%%%@ + @%%%#%%%*=---%%----*%%%%%%%@ + @%%%+===+%%%%%%%%%%%%#####%%%@ + @%%%+======+%%%%%%%%+-------#%%@ + @%%%========*%%%%%%%%*--------#%%@ + @%%%=======*%%%%%%%%%%%%*-------#%%@ + @%%#=====+%%%%+==+%%+--=*%%%+-----*%%@ + %%%#===============%%---------------*%%% + %%%#================%%*---------------+%%% + @%%%#=================*%%#=--------------+%%%@ + @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ From a6b33a16063d5cb5fdf6408b0e5081ceef756f95 Mon Sep 17 00:00:00 2001 From: xeroarch Date: Wed, 2 Oct 2024 14:12:52 -0400 Subject: [PATCH 03/10] updating --- src/logo/ascii/xeroarch.txt | 51 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 1f79ffe8c9..084cef4e29 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -1,22 +1,29 @@ - @@ - @%%%%@ - @%%%%%%@ - @%%%--#%%@ - @%%#----#%%@ - @%%#------*%%@ - @%%#--------*%%% - @%%*----------+%%@ - @%%%*-----+*-----+%%%@ - %%%+------%%------%%%%@ - @%%%#------=%%=----*%%%%%@ - @%%%#%%%*=---%%----*%%%%%%%@ - @%%%+===+%%%%%%%%%%%%#####%%%@ - @%%%+======+%%%%%%%%+-------#%%@ - @%%%========*%%%%%%%%*--------#%%@ - @%%%=======*%%%%%%%%%%%%*-------#%%@ - @%%#=====+%%%%+==+%%+--=*%%%+-----*%%@ - %%%#===============%%---------------*%%% - %%%#================%%*---------------+%%% - @%%%#=================*%%#=--------------+%%%@ - @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @@ + @%%%%@ + @%%%%%%@ + @%%%##%%%@ + @%%%#--*%%%@ + @%%%#----+%%%@@ + @%%%#------+%%%@ + @%%%*--------+%%%@ + @%%%*----------+%%%% + @%%%%*------------+%%%%@ + @%%%%*------==------=%%%%@ + @%%%%+-------##-------+%%%%@ + %%%%+-------=%%+-------%%%%%@ + @%%%%+--------+%%*------+%%%%%%@ + @%%%%%%%+------=%%+-----+%%%%%%%%@ + @%%%%*+#%%%%+---+%%+---=#%%%%%%%%%%@ + @%%%%+=====#%%%%%%%%%%%%%%%######%%%%@ + @%%%%+========*%%%%%%%%%%#---------#%%%@ + @%%%%+=========#%%%%%%%%%%#=---------*%%%@ + @%%%%+==========*%%%%%%%%%%*-----------*%%%@ + @%%%#+========*%%%%%%%%%%%%%%%%*---------*%%%@ + @%%%%=======+%%%%%*==*%%%%*--+#%%%%+-------*%%%@@ + @%%%%=======*##*+======+%%=------=+***-------*%%%@ + @%%%#===================+%%+-------------------+%%%@ + %%%%#=====================%%%=-------------------+%%%%@ + @%%%%#======================#%%%*-------------------+%%%%@ + %%%%%*++++++++++++++++++++++*%%%%%%#+++++++++++++++++#%%%%@ + @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \ No newline at end of file From 7b6433f79b0da4ee52c11f04bc16f5dc4cf376cc Mon Sep 17 00:00:00 2001 From: xeroarch Date: Wed, 2 Oct 2024 14:32:44 -0400 Subject: [PATCH 04/10] updating --- src/logo/ascii/xeroarch.txt | 53 +++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 084cef4e29..857a404ce0 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -1,29 +1,24 @@ - @@ - @%%%%@ - @%%%%%%@ - @%%%##%%%@ - @%%%#--*%%%@ - @%%%#----+%%%@@ - @%%%#------+%%%@ - @%%%*--------+%%%@ - @%%%*----------+%%%% - @%%%%*------------+%%%%@ - @%%%%*------==------=%%%%@ - @%%%%+-------##-------+%%%%@ - %%%%+-------=%%+-------%%%%%@ - @%%%%+--------+%%*------+%%%%%%@ - @%%%%%%%+------=%%+-----+%%%%%%%%@ - @%%%%*+#%%%%+---+%%+---=#%%%%%%%%%%@ - @%%%%+=====#%%%%%%%%%%%%%%%######%%%%@ - @%%%%+========*%%%%%%%%%%#---------#%%%@ - @%%%%+=========#%%%%%%%%%%#=---------*%%%@ - @%%%%+==========*%%%%%%%%%%*-----------*%%%@ - @%%%#+========*%%%%%%%%%%%%%%%%*---------*%%%@ - @%%%%=======+%%%%%*==*%%%%*--+#%%%%+-------*%%%@@ - @%%%%=======*##*+======+%%=------=+***-------*%%%@ - @%%%#===================+%%+-------------------+%%%@ - %%%%#=====================%%%=-------------------+%%%%@ - @%%%%#======================#%%%*-------------------+%%%%@ - %%%%%*++++++++++++++++++++++*%%%%%%#+++++++++++++++++#%%%%@ - @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \ No newline at end of file + @@ + @%%%%@ + @%%%%%%@ + @%%%--#%%@ + @%%#----#%%@ + @%%#------*%%@ + @%%#--------*%%% + @%%*----------+%%@ + @%%%*-----+*-----+%%%@ + %%%+------%%------%%%%@ + @%%%#------=%%=----*%%%%%@ + @%%%#%%%*=---%%----*%%%%%%%@ + @%%%+===+%%%%%%%%%%%%#####%%%@ + @%%%+======+%%%%%%%%+-------#%%@ + @%%%========*%%%%%%%%*--------#%%@ + @%%%=======*%%%%%%%%%%%%*-------#%%@ + @%%#=====+%%%%+==+%%+--=*%%%+-----*%%@ + %%%#===============%%---------------*%%% + %%%#================%%*---------------+%%% +@%%%#=================*%%#=--------------+%%%@ +@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + + From 82f47c67ab537e3d8a1f63130ac78eba715b4062 Mon Sep 17 00:00:00 2001 From: xeroarch Date: Wed, 2 Oct 2024 21:30:02 -0400 Subject: [PATCH 05/10] uploading xeroarch ascii logo --- src/logo/ascii/xeroarch.txt | 54 ++++++++++++++++++++++--------------- src/logo/builtin.c | 7 ++--- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 857a404ce0..5e8ba35c03 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -1,24 +1,34 @@ - @@ - @%%%%@ - @%%%%%%@ - @%%%--#%%@ - @%%#----#%%@ - @%%#------*%%@ - @%%#--------*%%% - @%%*----------+%%@ - @%%%*-----+*-----+%%%@ - %%%+------%%------%%%%@ - @%%%#------=%%=----*%%%%%@ - @%%%#%%%*=---%%----*%%%%%%%@ - @%%%+===+%%%%%%%%%%%%#####%%%@ - @%%%+======+%%%%%%%%+-------#%%@ - @%%%========*%%%%%%%%*--------#%%@ - @%%%=======*%%%%%%%%%%%%*-------#%%@ - @%%#=====+%%%%+==+%%+--=*%%%+-----*%%@ - %%%#===============%%---------------*%%% - %%%#================%%*---------------+%%% -@%%%#=================*%%#=--------------+%%%@ -@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +${c1} +${c1} @@ +${c1} @%%%%@ +${c1} @%%%%%%@ +${c1} @%%%%%%%%@ +${c1} @%%%#${c2}==${c1}*%%%@ +${c1} @%%%#${c2}====${c1}*%%%@ +${c1} @%%%#${c2}======${c1}*%%%% +${c1} @%%%%#${c2}========${c1}*%%%%@ +${c1} @%%%%#${c2}==========${c1}+%%%%@ +${c1} @%%%%*${c2}============${c1}+%%%%@ +${c1} @%%%%*${c2}==============${c1}=%%%%@ +${c1} @%%%%+${c2}=======${c1}++${c2}=======${c1}=%%%%@ +${c1} @%%%%+${c2}=======${c1}=#%=${c2}=======${c1}+%%%%@ +${c1} @%%%%+${c2}========${c1}+%%*${c2}=======${c1}=%%%%%@ +${c1} @%%%%+${c2}=========${c1}*%%#=${c2}======${c1}*%%%%%%@ +${c1} @%%%%%%%+${c2}=======${c1}+%%+${c2}======${c1}*%%%%%%%%@ +${c1} @%%%%${c3}+*${c1}%%%%%*${c2}====${c1}+%%*${c2}====${c1}=%%%%%%%%%%%@ +${c1} @%%%#${c3}+=====${c1}#%%%%%%%%%%%%%%%%%%%%%%%%%%%@ +${c1} @%%%#${c3}+=========${c1}%%%%%%%%%%%%${c4}==========${c1}*%%%@ +${c1} @%%%%#${c3}==========+${c1}%%%%%%%%%%%%${c4}===========${c1}*%%%%@ +${c1} @%%%%%${c3}===========+${c1}%%%%%%%%%%%%${c4}============${c1}*%%%%@ +${c1} @%%%%#${c3}==========+*${c1}%%%%%%%%%%%%%%*=${c4}==========${c1}+%%%%@ +${c1} @%%%%#${c3}========+${c1}#%%%%%*#%%%%%%%*#%%%%%+${c4}========${c1}+%%%%@ +${c1} @%%%%*${c3}=======*${c1}%%%%#*${c3}=====${c1}*%%*${c4}=====${c1}=##%%%+${c4}-------${c1}=%%%%@ +${c1} @%%%%*${c3}====================${c1}*%%+${c4}====================${c1}=%%%%@ +${c1} @%%%%*${c3}=====================${c1}*%%#=${c4}====================${c1}=%%%%@ +${c1} @%%%%%*${c3}======================${c1}+%%%*${c4}=====================${c1}=#%%%%@ +${c1}@@%%%%+${c3}========================${c1}*%%%%+${c4}====================${c1}=#%%%@@ +${c1}@%%%%#${c3}*************************${c1}#%%%%%%%#${c4}******************${c1}#%%%%@ +${c1}@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ +${c1} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ diff --git a/src/logo/builtin.c b/src/logo/builtin.c index efb361355c..c14ef2723a 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -4790,9 +4790,10 @@ static const FFlogo X[] = { .names = {"XeroArch"}, .lines = FASTFETCH_DATATEXT_LOGO_XEROARCH, .colors = { - FF_COLOR_FG_256 "15", - FF_COLOR_FG_256 "14", FF_COLOR_FG_256 "16", + FF_COLOR_FG_256 "51", + FF_COLOR_FG_256 "15", + FF_COLOR_FG_256 "51", } }, //Xray_OS @@ -4800,7 +4801,7 @@ static const FFlogo X[] = { .names = {"Xray_OS"}, .lines = FASTFETCH_DATATEXT_LOGO_XRAY_OS, .colors = { - FF_COLOR_FG_256 "15", + FF_COLOR_FG_256 "16", FF_COLOR_FG_256 "14", FF_COLOR_FG_256 "16", } From 05075a2d6596b80439ce296998c075acf11b8acf Mon Sep 17 00:00:00 2001 From: xeroarch Date: Fri, 4 Oct 2024 23:14:12 -0400 Subject: [PATCH 06/10] upgrading fetch ascii logo --- src/logo/ascii/xeroarch.txt | 50 ++++++++++++++----------------------- src/logo/builtin.c | 6 +++-- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 5e8ba35c03..3b173fbe9b 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -1,34 +1,22 @@ ${c1} -${c1} @@ -${c1} @%%%%@ -${c1} @%%%%%%@ -${c1} @%%%%%%%%@ -${c1} @%%%#${c2}==${c1}*%%%@ -${c1} @%%%#${c2}====${c1}*%%%@ -${c1} @%%%#${c2}======${c1}*%%%% -${c1} @%%%%#${c2}========${c1}*%%%%@ -${c1} @%%%%#${c2}==========${c1}+%%%%@ -${c1} @%%%%*${c2}============${c1}+%%%%@ -${c1} @%%%%*${c2}==============${c1}=%%%%@ -${c1} @%%%%+${c2}=======${c1}++${c2}=======${c1}=%%%%@ -${c1} @%%%%+${c2}=======${c1}=#%=${c2}=======${c1}+%%%%@ -${c1} @%%%%+${c2}========${c1}+%%*${c2}=======${c1}=%%%%%@ -${c1} @%%%%+${c2}=========${c1}*%%#=${c2}======${c1}*%%%%%%@ -${c1} @%%%%%%%+${c2}=======${c1}+%%+${c2}======${c1}*%%%%%%%%@ -${c1} @%%%%${c3}+*${c1}%%%%%*${c2}====${c1}+%%*${c2}====${c1}=%%%%%%%%%%%@ -${c1} @%%%#${c3}+=====${c1}#%%%%%%%%%%%%%%%%%%%%%%%%%%%@ -${c1} @%%%#${c3}+=========${c1}%%%%%%%%%%%%${c4}==========${c1}*%%%@ -${c1} @%%%%#${c3}==========+${c1}%%%%%%%%%%%%${c4}===========${c1}*%%%%@ -${c1} @%%%%%${c3}===========+${c1}%%%%%%%%%%%%${c4}============${c1}*%%%%@ -${c1} @%%%%#${c3}==========+*${c1}%%%%%%%%%%%%%%*=${c4}==========${c1}+%%%%@ -${c1} @%%%%#${c3}========+${c1}#%%%%%*#%%%%%%%*#%%%%%+${c4}========${c1}+%%%%@ -${c1} @%%%%*${c3}=======*${c1}%%%%#*${c3}=====${c1}*%%*${c4}=====${c1}=##%%%+${c4}-------${c1}=%%%%@ -${c1} @%%%%*${c3}====================${c1}*%%+${c4}====================${c1}=%%%%@ -${c1} @%%%%*${c3}=====================${c1}*%%#=${c4}====================${c1}=%%%%@ -${c1} @%%%%%*${c3}======================${c1}+%%%*${c4}=====================${c1}=#%%%%@ -${c1}@@%%%%+${c3}========================${c1}*%%%%+${c4}====================${c1}=#%%%@@ -${c1}@%%%%#${c3}*************************${c1}#%%%%%%%#${c4}******************${c1}#%%%%@ -${c1}@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ -${c1} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + ████ +${c1} ███${c2}▓▓${c1}███ +${c1} ███${c2}▓▓▓▓${c1}███ +${c1} ███${c2}▓▓▓▓▓▓${c1}███ +${c1} ███${c2}▓▓▓▓▓▓▓▓${c1}███ +${c1} ███${c2}▓▓▓▓▓▓▓▓▓▓${c1}███ +${c1} ███${c2}▓▓▓▓▓▓▓▓▓▓▓▓${c1}███ +${c1} ███${c2}▓▓▓▓▓▓${c1}██${c2}▓▓▓▓▓▓${c1}▓██ +${c1} ███${c2}▓▓▓▓▓▓${c1}████${c2}▓▓▓▓▓▓${c1}▓██ +${c1} ██${c2}▓▓▓▓▓▓▓${c1}█▓${c3}▓▓${c1}▓█${c2}▓▓▓▓▓▓${c1}▓██ +${c1} █████▓▒▒▒██${c3}▓${c4}▒▒${c3}▓${c1}██▒▒▒▓█████ +${c1} ███${c6}▓▓▓▓▓${c1}████${c3}▓${c4}▒▒▒▒${c3}▓${c1}▓███${c6}▓▓▓▓▓${c1}███ +${c1} ███${c6}▓▓▓▓▓▓▓▓▓${c1}███▓▓███${c6}▓▓▓▓▓▓▓▓▓${c1}███ +${c1} ███${c6}▓▓▓▓▓▓▓${c2}▓▓${c6}▓▓▓▓▓${c1}█${c6}▓▓▓▓▓▓▓▓▓▓▓▓▓${c1}███ +${c1} ███${c6}▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c6}▓▓▓${c1}▓${c6}▓▓▓▓${c4}()${c6}▓▓▓▓▓▓▓▓${c1}███ +${c1} ███${c6}▓▓▓▓▓${c2}▓▓${c5}▒▒▒▒▒▒${c6}${c2}▓▓${c6}▓${c1}▓${c6}▓▓${c3}()${c6}▓▓${c3}()${c6}▓▓▓▓▓▓▓${c1}███ +${c1}███${c6}▓▓▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c6}▓▓▓${c1}▓${c6}▓▓▓▓${c4}()${c6}▓▓▓▓▓▓▓▓▓▓${c1}███ +${c1}██${c6}▓▓▓▓▓▓▓▓▓▓▓${c2}▓▓${c6}▓▓▓▓▓${c1}▓${c6}▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓${c1}██ +${c1}████████████████████████████████████████ diff --git a/src/logo/builtin.c b/src/logo/builtin.c index c14ef2723a..5235393d37 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -4791,9 +4791,11 @@ static const FFlogo X[] = { .lines = FASTFETCH_DATATEXT_LOGO_XEROARCH, .colors = { FF_COLOR_FG_256 "16", - FF_COLOR_FG_256 "51", + FF_COLOR_FG_256 "14", + FF_COLOR_FG_256 "50", + FF_COLOR_FG_256 "93", + FF_COLOR_FG_256 "46", FF_COLOR_FG_256 "15", - FF_COLOR_FG_256 "51", } }, //Xray_OS From 3c8b3d6ae80d268f88592c03c43e56b33f5fcd47 Mon Sep 17 00:00:00 2001 From: xeroarch Date: Fri, 4 Oct 2024 23:28:57 -0400 Subject: [PATCH 07/10] fixing a very small issue --- src/logo/ascii/xeroarch.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 3b173fbe9b..5ae37c806a 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -8,7 +8,7 @@ ${c1} ███${c2}▓▓▓▓▓▓▓▓▓▓${c1}███ ${c1} ███${c2}▓▓▓▓▓▓▓▓▓▓▓▓${c1}███ ${c1} ███${c2}▓▓▓▓▓▓${c1}██${c2}▓▓▓▓▓▓${c1}▓██ ${c1} ███${c2}▓▓▓▓▓▓${c1}████${c2}▓▓▓▓▓▓${c1}▓██ -${c1} ██${c2}▓▓▓▓▓▓▓${c1}█▓${c3}▓▓${c1}▓█${c2}▓▓▓▓▓▓${c1}▓██ +${c1} ██▓${c2}▓▓▓▓▓▓${c1}█▓${c3}▓▓${c1}▓█${c2}▓▓▓▓▓▓${c1}▓██ ${c1} █████▓▒▒▒██${c3}▓${c4}▒▒${c3}▓${c1}██▒▒▒▓█████ ${c1} ███${c6}▓▓▓▓▓${c1}████${c3}▓${c4}▒▒▒▒${c3}▓${c1}▓███${c6}▓▓▓▓▓${c1}███ ${c1} ███${c6}▓▓▓▓▓▓▓▓▓${c1}███▓▓███${c6}▓▓▓▓▓▓▓▓▓${c1}███ From c1a88899c7bf827af7a005acb3807c87fde02ddb Mon Sep 17 00:00:00 2001 From: xeroarch Date: Fri, 4 Oct 2024 23:36:43 -0400 Subject: [PATCH 08/10] removing unecessary line --- src/logo/ascii/ascii-art.txt | 45 ------------------------------------ src/logo/ascii/xeroarch.txt | 3 +-- 2 files changed, 1 insertion(+), 47 deletions(-) delete mode 100755 src/logo/ascii/ascii-art.txt diff --git a/src/logo/ascii/ascii-art.txt b/src/logo/ascii/ascii-art.txt deleted file mode 100755 index d72aeac27b..0000000000 --- a/src/logo/ascii/ascii-art.txt +++ /dev/null @@ -1,45 +0,0 @@ - - @@%%@@ - @%%%%%%@ - @%%%%%%%%%@ - @%%%%%%%%%%@ - @@%%%%%*=%%%%%%@ - @@%%%%%*-:=%%%%%%@ - @%%%%%%*::::=%%%%%%@ - @%%%%%%*::::::=%%%%%%@ - @%%%%%%+::::::::=%%%%%%@ - @%%%%%%+::::::::::-%%%%%%@ - @%%%%%%=::::::::::::-%%%%%%@ - @%%%%%%=:::::::::::::::%%%%%%@ - @%%%%%%=::::::::::::::::-%%%%%%@ - @%%%%%%=:::::::::::::::::::#%%%%%@ - @%%%%%%=::::::::::::::::::::-#%%%%%@ - @%%%%%%-::::::::::**:::::::::::*%%%%%@@ - @%%%%%%-::::::::::=%%=:::::::::::#%%%%%@ - @%%%%%%%-:::::::::::*%%%:::::::::::=%%%%%%%@ - @@%%%%%%-:::::::::::=%%%%=::::::::::-%%%%%%%%@ - @%%%%%%#:::::::::::::*%%%%#::::::::::+%%%%%%%%%@ - @%%%%%%%=-::::::::::::*%%%%*:::::::::-%%%%%%%%%%%@ - @%%%%%%%%%%%*:::::::::::%%%%=::::::::-%%%%%%%%%%%%%@ - @%%%%%%%%%%%%%%%*-:::::::%%%%-:::::::*%%%%%%%%%%%%%%%@ - @%%%%%%*====*%%%%%%%+:-+#%%%%%%%*-:=*%%%%%%%%%%%%%%%%%%@ - @%%%%%%*========*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @%%%%%%*============*%%%%%%%%%%%%%%%%%%%+-::::::::::=%%%%%%@ - @%%%%%%*==============%%%%%%%%%%%%%%%%%%-:::::::::::::-%%%%%%@ - @%%%%%%+===============%%%%%%%%%%%%%%%%%%=::::::::::::::-%%%%%%@ - @%%%%%%+================%%%%%%%%%%%%%%%%%%=:::::::::::::::-#%%%%%@@ - @%%%%%%+=================#%%%%%%%%%%%%%%%%%-::::::::::::::::-#%%%%%@ - %%%%%%%===============+%%%%%%%%%%%%%%%%%%%%%%%%=:::::::::::::::#%%%%%%@ - @%%%%%%=============#%%%%%%%%*%%%%%%%%%%%%*%%%%%%%%#-::::::::::::#%%%%%%@ - @%%%%%%%============#%%%%%%%#+====*#%%%%#*=:::-*%%%%%%%#=:::::::::::*%%%%%%@ - @%%%%%%%===========#%%%%%%*+=========%%%%=::::::::-*##%%%%#=::::::::::*%%%%%%@ - @%%%%%%%==============================%%%%=:::::::::::::::::::::::::::::+%%%%%%@ - @%%%%%%%===============================%%%%=::::::::::::::::::::::::::::::+%%%%%%@ - @%%%%%%#================================%%%%%-::::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%#=================================*%%%%#-::::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%#==================================+%%%%%%=::::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%#====================================#%%%%%%%*-::::::::::::::::::::::::::::=%%%%%%@ - @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ - @@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@ - diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 5ae37c806a..cfd350a697 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -1,5 +1,4 @@ -${c1} - ████ +${c1} ████ ${c1} ███${c2}▓▓${c1}███ ${c1} ███${c2}▓▓▓▓${c1}███ ${c1} ███${c2}▓▓▓▓▓▓${c1}███ From e4de9feb1e7a1354ffc1416d9ad9124deda7e7ef Mon Sep 17 00:00:00 2001 From: xeroarch Date: Fri, 4 Oct 2024 23:38:10 -0400 Subject: [PATCH 09/10] removing trailing lines --- src/logo/ascii/xeroarch.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index cfd350a697..1f094ea061 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -16,6 +16,4 @@ ${c1} ███${c6}▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c ${c1} ███${c6}▓▓▓▓▓${c2}▓▓${c5}▒▒▒▒▒▒${c6}${c2}▓▓${c6}▓${c1}▓${c6}▓▓${c3}()${c6}▓▓${c3}()${c6}▓▓▓▓▓▓▓${c1}███ ${c1}███${c6}▓▓▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c6}▓▓▓${c1}▓${c6}▓▓▓▓${c4}()${c6}▓▓▓▓▓▓▓▓▓▓${c1}███ ${c1}██${c6}▓▓▓▓▓▓▓▓▓▓▓${c2}▓▓${c6}▓▓▓▓▓${c1}▓${c6}▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓${c1}██ -${c1}████████████████████████████████████████ - - +${c1}████████████████████████████████████████ \ No newline at end of file From 12245a8b7cb0c93a4c025862a80579e858e282dc Mon Sep 17 00:00:00 2001 From: xeroarch Date: Mon, 14 Oct 2024 16:06:42 -0400 Subject: [PATCH 10/10] fixing erroneous colors in the logo --- .codespellrc | 2 +- CHANGELOG.md | 53 ++++ CMakeLists.txt | 176 ++++++++++-- completions/fastfetch.bash | 3 + debian/changelog | 6 + debian/files | 2 +- doc/json_schema.json | 9 +- presets/all.jsonc | 4 +- presets/ci.jsonc | 4 +- run.sh | 28 +- src/common/init.c | 2 +- src/common/io/io.h | 13 + src/common/io/io_unix.c | 51 +++- src/common/io/io_windows.c | 57 +++- src/common/modules.c | 2 + src/common/netif/netif_linux.c | 6 +- src/common/parsing.c | 42 +++ src/common/parsing.h | 1 + src/common/processing_linux.c | 53 +++- src/common/sysctl.c | 36 +++ src/common/sysctl.h | 6 + src/data/help.json | 27 ++ src/detection/battery/battery.h | 1 + src/detection/battery/battery_android.c | 26 +- src/detection/battery/battery_apple.c | 7 + src/detection/battery/battery_bsd.c | 5 +- src/detection/battery/battery_linux.c | 139 +++++----- src/detection/battery/battery_windows.c | 9 + src/detection/bios/bios_nosupport.c | 2 +- .../bluetoothradio/bluetoothradio_linux.c | 1 + src/detection/board/board_linux.c | 8 +- src/detection/cpu/cpu_nosupport.c | 2 +- src/detection/cpu/cpu_obsd.c | 19 ++ src/detection/cpuusage/cpuusage_bsd.c | 16 ++ src/detection/cpuusage/cpuusage_nosupport.c | 2 +- src/detection/disk/disk_bsd.c | 9 + src/detection/disk/disk_nosupport.c | 2 +- src/detection/diskio/diskio_nosupport.c | 2 +- src/detection/displayserver/displayserver.c | 4 +- src/detection/displayserver/displayserver.h | 4 +- .../displayserver/displayserver_android.c | 6 +- .../displayserver/displayserver_apple.c | 55 +++- .../displayserver/displayserver_windows.c | 3 +- .../displayserver/linux/displayserver_linux.c | 2 +- src/detection/displayserver/linux/drm.c | 6 +- .../linux/wayland/global-output.c | 3 +- .../displayserver/linux/wayland/kde-output.c | 3 +- .../displayserver/linux/wayland/wayland.c | 2 +- .../displayserver/linux/wayland/zwlr-output.c | 3 +- src/detection/displayserver/linux/wmde.c | 29 +- src/detection/displayserver/linux/xcb.c | 13 +- src/detection/displayserver/linux/xlib.c | 13 +- src/detection/dns/dns_linux.c | 5 +- src/detection/gamepad/gamepad_bsd.c | 5 +- src/detection/gamepad/gamepad_linux.c | 2 +- src/detection/gamepad/gamepad_windows.c | 14 +- src/detection/gpu/gpu_linux.c | 3 +- src/detection/host/host_nosupport.c | 2 +- src/detection/host/host_obsd.c | 19 ++ src/detection/keyboard/keyboard.h | 9 + src/detection/keyboard/keyboard_apple.c | 42 +++ src/detection/keyboard/keyboard_bsd.c | 47 ++++ src/detection/keyboard/keyboard_linux.c | 57 ++++ src/detection/keyboard/keyboard_nosupport.c | 6 + src/detection/keyboard/keyboard_windows.c | 91 ++++++ src/detection/loadavg/loadavg_bsd.c | 6 +- src/detection/localip/localip.h | 21 ++ src/detection/localip/localip_linux.c | 63 ++++- src/detection/localip/localip_windows.c | 26 +- src/detection/memory/memory_nosupport.c | 2 +- src/detection/memory/memory_obsd.c | 17 ++ src/detection/memory/memory_sunos.c | 30 +- src/detection/mouse/mouse.h | 9 + src/detection/mouse/mouse_apple.c | 42 +++ src/detection/mouse/mouse_bsd.c | 47 ++++ src/detection/mouse/mouse_linux.c | 44 +++ src/detection/mouse/mouse_nosupport.c | 6 + src/detection/mouse/mouse_windows.c | 89 ++++++ src/detection/netio/netio_nosupport.c | 2 +- src/detection/opencl/opencl.c | 21 +- src/detection/opengl/opengl_linux.c | 11 +- src/detection/os/os_obsd.c | 7 + src/detection/packages/packages_bsd.c | 2 +- src/detection/packages/packages_nosupport.c | 2 +- src/detection/packages/packages_obsd.c | 31 +++ .../physicaldisk/physicaldisk_linux.c | 259 +++++++++--------- .../poweradapter/poweradapter_linux.c | 53 ++-- src/detection/processes/processes_obsd.c | 14 + src/detection/swap/swap_obsd.c | 30 ++ src/detection/terminalfont/terminalfont.c | 2 +- src/detection/terminalshell/terminalshell.c | 20 +- .../terminalshell/terminalshell_linux.c | 37 ++- src/detection/tpm/tpm_windows.c | 7 +- src/detection/users/users_nosupport.c | 7 + src/detection/version/version.c | 7 +- src/detection/zpool/zpool.h | 2 +- src/detection/zpool/zpool_linux.c | 3 +- src/logo/ascii/center.txt | 26 +- src/logo/ascii/cyberos.txt | 30 +- src/logo/ascii/eweos.txt | 15 + src/logo/ascii/midos.txt | 20 ++ src/logo/ascii/valhalla.txt | 10 + src/logo/ascii/xeroarch.txt | 38 +-- src/logo/builtin.c | 38 ++- src/modules/battery/battery.c | 34 ++- src/modules/display/display.c | 6 +- src/modules/keyboard/keyboard.c | 142 ++++++++++ src/modules/keyboard/keyboard.h | 9 + src/modules/keyboard/option.h | 11 + src/modules/localip/localip.c | 54 +++- src/modules/localip/option.h | 1 + src/modules/memory/memory.c | 2 +- src/modules/modules.h | 2 + src/modules/monitor/monitor.c | 2 +- src/modules/mouse/mouse.c | 142 ++++++++++ src/modules/mouse/mouse.h | 9 + src/modules/mouse/option.h | 11 + src/modules/options.h | 2 + src/modules/os/os.c | 2 + src/modules/swap/swap.c | 2 +- src/modules/uptime/uptime.c | 43 +-- src/modules/zpool/zpool.c | 9 +- src/options/general.c | 4 +- src/options/general.h | 2 +- src/options/modules.c | 4 + src/options/modules.h | 2 + src/util/binary_linux.c | 2 +- src/util/platform/FFPlatform_unix.c | 8 +- src/util/platform/FFPlatform_windows.c | 13 + 129 files changed, 2340 insertions(+), 555 deletions(-) create mode 100644 src/detection/cpu/cpu_obsd.c create mode 100644 src/detection/host/host_obsd.c create mode 100644 src/detection/keyboard/keyboard.h create mode 100644 src/detection/keyboard/keyboard_apple.c create mode 100644 src/detection/keyboard/keyboard_bsd.c create mode 100644 src/detection/keyboard/keyboard_linux.c create mode 100644 src/detection/keyboard/keyboard_nosupport.c create mode 100644 src/detection/keyboard/keyboard_windows.c create mode 100644 src/detection/memory/memory_obsd.c create mode 100644 src/detection/mouse/mouse.h create mode 100644 src/detection/mouse/mouse_apple.c create mode 100644 src/detection/mouse/mouse_bsd.c create mode 100644 src/detection/mouse/mouse_linux.c create mode 100644 src/detection/mouse/mouse_nosupport.c create mode 100644 src/detection/mouse/mouse_windows.c create mode 100644 src/detection/os/os_obsd.c create mode 100644 src/detection/packages/packages_obsd.c create mode 100644 src/detection/processes/processes_obsd.c create mode 100644 src/detection/swap/swap_obsd.c create mode 100644 src/detection/users/users_nosupport.c create mode 100644 src/logo/ascii/eweos.txt create mode 100644 src/logo/ascii/midos.txt create mode 100644 src/logo/ascii/valhalla.txt create mode 100644 src/modules/keyboard/keyboard.c create mode 100644 src/modules/keyboard/keyboard.h create mode 100644 src/modules/keyboard/option.h create mode 100644 src/modules/mouse/mouse.c create mode 100644 src/modules/mouse/mouse.h create mode 100644 src/modules/mouse/option.h diff --git a/.codespellrc b/.codespellrc index 087150a6d5..2de890a809 100644 --- a/.codespellrc +++ b/.codespellrc @@ -2,4 +2,4 @@ check-filenames = builtin = clear,rare,usage,informal skip = */.git,*/cmake-build-*,*/.idea,*/completions,*/presets,*/screenshots,*/tests,*/3rdparty,*/logo/ascii -ignore-words-list = iterm,compiletime,unknwn,pengwin,siduction,master,sur,doas,conexant +ignore-words-list = iterm,compiletime,unknwn,pengwin,siduction,master,slave,sur,doas,conexant,ags diff --git a/CHANGELOG.md b/CHANGELOG.md index 57eda8efec..0f1bae02e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,56 @@ +# 2.28.0 + +Features: +* Add new module `Mouse` and `Keyboard` which display connected mice and keyboards +* Support remaining time detection (Battery) +* Report if AC is connected (Battery, Linux) +* Report platform API used for display detection (Display) + * Mainly for debugging +* Report Wine version when running in Wine (Kernel, Windows) + +Bugfixes: +* Fix used memory size detection (Memory, OpenBSD) +* Don't report invalid fragmentation percentage when fails to detect it (Zpool) + +Logos: +* Add eweOS +* Add MidOS + +# 2.27.1 + +Bugfixes: +* Fix invalid display name detection on GNOME, wayland (Display, Linux) + +# 2.27.0 + +Changes: +* We now print `"` instead of `″` when displaying diagonal length in inches, so that the character can be correctly displayed in Linux console (Display) +* All detection code of `monitor` module is merged into `display` module. Now `monitor` just prints the same information as `display` with different format. Notably: + * The resolution reported by `monitor` module is now current resolution instead of native / maximum resolution. PPI is calculated based on current resolution too. + * The refresh rate reported by `monitor` module is the current refresh rate. + +Features: +* Add basic, highly experimental support of OpenBSD (OpenBSD) +* Improve support for Raspberry pi (CPU / GPU, Linux) +* Detect SOC name, instead of displaying components used in the SOC, if available (CPU, Linux) +* Add option `--brightness-compact` to display multiple brightness values in one line (Brightness) +* Add `day-pretty` (#1305, DateTime) +* Support network interface adapter flag detection (#1315, LocalIP) + * Enable it with `--localip-show-flags` + +Bugfixes: +* Remove trailing newline in GPU name for Raspberry pi (#1303, GPU, Linux) +* Fix a possible buffer overflow (GPU, Linux) +* Fix CPU temp incorrectly reported as 0 celsius (#1308, CPU, Linux) +* Correctly report `TPM device is not found` error (#1314, TPM, Windows) +* Fix errors when triggering shell completion with python3 uninstalled (#1310) + * To package managers: as shell completion scripts of fastfetch use python3, it should be added as an optional dependency of fastfetch +* Fix possible crashes when detecting term font of kitty (#1321, TerminalFont, Linux) + +Logos: +* Add XeroArch +* Add ValhallaOS + # 2.26.1 Features: diff --git a/CMakeLists.txt b/CMakeLists.txt index dd95d42917..5a6683df81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.26.1 + VERSION 2.27.1 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" @@ -18,6 +18,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(LINUX TRUE CACHE BOOL "..." FORCE) # LINUX means GNU/Linux, not just the kernel elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") set(FreeBSD TRUE CACHE BOOL "..." FORCE) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") + set(OpenBSD TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") set(SunOS TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) @@ -44,30 +46,30 @@ include(CheckIncludeFile) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR WIN32 OR ANDROID OR SunOS" OFF) -cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD" OFF) -cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XCB "Enable xcb" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_X11 "Enable x11" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR WIN32 OR ANDROID OR SunOS" OFF) +cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD" OFF) +cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_XCB "Enable xcb" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_X11 "Enable x11" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX" OFF) -cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR SunOS" OFF) +cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX" OFF) -cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR APPLE OR WIN32 OR SunOS" OFF) -cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR APPLE OR SunOS" OFF) +cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR OpenBSD OR APPLE OR WIN32 OR SunOS" OFF) +cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR OpenBSD OR APPLE OR SunOS" OFF) cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) -cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR WIN32 OR SunOS" OFF) -cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR FreeBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR WIN32 OR ANDROID OR SunOS" OFF) +cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR WIN32 OR SunOS" OFF) +cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR WIN32 OR ANDROID OR SunOS" OFF) cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF) -cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR SunOS" OFF) +cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR OpenBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF) cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID" OFF) @@ -377,6 +379,7 @@ set(LIBFASTFETCH_SRC src/modules/initsystem/initsystem.c src/modules/gamepad/gamepad.c src/modules/kernel/kernel.c + src/modules/keyboard/keyboard.c src/modules/lm/lm.c src/modules/loadavg/loadavg.c src/modules/locale/locale.c @@ -400,6 +403,7 @@ set(LIBFASTFETCH_SRC src/modules/sound/sound.c src/modules/swap/swap.c src/modules/media/media.c + src/modules/mouse/mouse.c src/modules/terminal/terminal.c src/modules/terminaltheme/terminaltheme.c src/modules/terminalfont/terminalfont.c @@ -476,6 +480,7 @@ if(LINUX) src/detection/host/host_linux.c src/detection/icons/icons_linux.c src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_linux.c src/detection/libc/libc_linux.c src/detection/lm/lm_linux.c src/detection/loadavg/loadavg_linux.c @@ -484,6 +489,7 @@ if(LINUX) src/detection/gamepad/gamepad_linux.c src/detection/media/media_linux.c src/detection/memory/memory_linux.c + src/detection/mouse/mouse_linux.c src/detection/netio/netio_linux.c src/detection/opengl/opengl_linux.c src/detection/os/os_linux.c @@ -540,6 +546,7 @@ elseif(ANDROID) src/detection/host/host_android.c src/detection/icons/icons_nosupport.c src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_nosupport.c src/detection/libc/libc_android.c src/detection/lm/lm_nosupport.c src/detection/loadavg/loadavg_linux.c @@ -548,6 +555,7 @@ elseif(ANDROID) src/detection/gamepad/gamepad_nosupport.c src/detection/media/media_nosupport.c src/detection/memory/memory_linux.c + src/detection/mouse/mouse_nosupport.c src/detection/netio/netio_linux.c src/detection/opengl/opengl_linux.c src/detection/os/os_android.c @@ -620,6 +628,7 @@ elseif(FreeBSD) src/detection/lm/lm_linux.c src/detection/icons/icons_linux.c src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_bsd.c src/detection/libc/libc_bsd.c src/detection/loadavg/loadavg_bsd.c src/detection/locale/locale_linux.c @@ -627,6 +636,7 @@ elseif(FreeBSD) src/detection/gamepad/gamepad_bsd.c src/detection/media/media_linux.c src/detection/memory/memory_bsd.c + src/detection/mouse/mouse_bsd.c src/detection/netio/netio_bsd.c src/detection/opengl/opengl_linux.c src/detection/os/os_linux.c @@ -653,6 +663,87 @@ elseif(FreeBSD) src/util/platform/FFPlatform_unix.c src/util/binary_linux.c ) +elseif(OpenBSD) + list(APPEND LIBFASTFETCH_SRC + src/common/dbus.c + src/common/io/io_unix.c + src/common/netif/netif_bsd.c + src/common/networking_linux.c + src/common/processing_linux.c + src/common/sysctl.c + src/detection/battery/battery_nosupport.c + src/detection/bios/bios_nosupport.c + src/detection/bluetooth/bluetooth_nosupport.c + src/detection/bluetoothradio/bluetoothradio_nosupport.c + src/detection/board/board_nosupport.c + src/detection/bootmgr/bootmgr_nosupport.c + src/detection/brightness/brightness_nosupport.c + src/detection/btrfs/btrfs_nosupport.c + src/detection/chassis/chassis_nosupport.c + src/detection/cpu/cpu_obsd.c + src/detection/cpucache/cpucache_nosupport.c + src/detection/cpuusage/cpuusage_bsd.c + src/detection/cursor/cursor_linux.c + src/detection/disk/disk_bsd.c + src/detection/dns/dns_linux.c + src/detection/physicaldisk/physicaldisk_nosupport.c + src/detection/physicalmemory/physicalmemory_nosupport.c + src/detection/diskio/diskio_nosupport.c + src/detection/displayserver/linux/displayserver_linux.c + src/detection/displayserver/linux/drm.c + src/detection/displayserver/linux/wayland/wayland.c + src/detection/displayserver/linux/wayland/global-output.c + src/detection/displayserver/linux/wayland/zwlr-output.c + src/detection/displayserver/linux/wayland/kde-output.c + src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c + src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c + src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c + src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c + src/detection/displayserver/linux/wmde.c + src/detection/displayserver/linux/xcb.c + src/detection/displayserver/linux/xlib.c + src/detection/font/font_linux.c + src/detection/gpu/gpu_nosupport.c + src/detection/gtk_qt/gtk.c + src/detection/host/host_obsd.c + src/detection/lm/lm_nosupport.c + src/detection/icons/icons_linux.c + src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_nosupport.c + src/detection/libc/libc_nosupport.c + src/detection/loadavg/loadavg_bsd.c + src/detection/locale/locale_linux.c + src/detection/localip/localip_linux.c + src/detection/gamepad/gamepad_nosupport.c + src/detection/media/media_linux.c + src/detection/memory/memory_obsd.c + src/detection/mouse/mouse_nosupport.c + src/detection/netio/netio_nosupport.c + src/detection/opengl/opengl_linux.c + src/detection/os/os_obsd.c + src/detection/packages/packages_obsd.c + src/detection/poweradapter/poweradapter_nosupport.c + src/detection/processes/processes_obsd.c + src/detection/gtk_qt/qt.c + src/detection/sound/sound_linux.c + src/detection/swap/swap_obsd.c + src/detection/terminalfont/terminalfont_linux.c + src/detection/terminalshell/terminalshell_linux.c + src/detection/terminalsize/terminalsize_linux.c + src/detection/theme/theme_linux.c + src/detection/tpm/tpm_nosupport.c + src/detection/uptime/uptime_bsd.c + src/detection/users/users_nosupport.c + src/detection/wallpaper/wallpaper_linux.c + src/detection/wifi/wifi_nosupport.c + src/detection/wm/wm_nosupport.c + src/detection/de/de_linux.c + src/detection/wmtheme/wmtheme_linux.c + src/detection/camera/camera_nosupport.c + src/detection/zpool/zpool_nosupport.c + src/util/platform/FFPlatform_unix.c + src/util/binary_linux.c + ) elseif(APPLE) list(APPEND LIBFASTFETCH_SRC src/common/io/io_unix.c @@ -685,6 +776,7 @@ elseif(APPLE) src/detection/host/host_apple.c src/detection/icons/icons_nosupport.c src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_apple.c src/detection/lm/lm_nosupport.c src/detection/loadavg/loadavg_bsd.c src/detection/libc/libc_apple.c @@ -693,6 +785,7 @@ elseif(APPLE) src/detection/gamepad/gamepad_apple.c src/detection/media/media_apple.m src/detection/memory/memory_apple.c + src/detection/mouse/mouse_apple.c src/detection/netio/netio_bsd.c src/detection/opengl/opengl_apple.c src/detection/os/os_apple.m @@ -751,6 +844,7 @@ elseif(WIN32) src/detection/host/host_windows.c src/detection/icons/icons_windows.c src/detection/initsystem/initsystem_nosupport.c + src/detection/keyboard/keyboard_windows.c src/detection/libc/libc_windows.cpp src/detection/lm/lm_nosupport.c src/detection/loadavg/loadavg_nosupport.c @@ -759,6 +853,7 @@ elseif(WIN32) src/detection/gamepad/gamepad_windows.c src/detection/media/media_windows.c src/detection/memory/memory_windows.c + src/detection/mouse/mouse_windows.c src/detection/physicalmemory/physicalmemory_linux.c src/detection/netio/netio_windows.c src/detection/opengl/opengl_windows.c @@ -835,6 +930,7 @@ elseif(SunOS) src/detection/host/host_windows.c src/detection/icons/icons_linux.c src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_nosupport.c src/detection/libc/libc_nosupport.c src/detection/lm/lm_nosupport.c src/detection/loadavg/loadavg_sunos.c @@ -843,6 +939,7 @@ elseif(SunOS) src/detection/gamepad/gamepad_nosupport.c src/detection/media/media_linux.c src/detection/memory/memory_sunos.c + src/detection/mouse/mouse_nosupport.c src/detection/netio/netio_sunos.c src/detection/opengl/opengl_linux.c src/detection/os/os_sunos.c @@ -945,13 +1042,16 @@ if(FreeBSD AND EXISTS "/usr/local/bin/objdump") endif() endif() -target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__=1 _FILE_OFFSET_BITS=64) -if(WIN32) - target_compile_definitions(libfastfetch PUBLIC WIN32_LEAN_AND_MEAN=1) +if(LINUX OR ANDROID) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _ATFILE_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64) +elseif(WIN32) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN=1 _WIN32_WINNT=0x0A00) elseif(APPLE) - target_compile_definitions(libfastfetch PUBLIC _DARWIN_C_SOURCE) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _DARWIN_C_SOURCE) +elseif(OpenBSD) + target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE) elseif(SunOS) - target_compile_definitions(libfastfetch PUBLIC __EXTENSIONS__ _POSIX_C_SOURCE=1) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE) endif() if(HAVE_STATX) @@ -1097,10 +1197,17 @@ ff_lib_enable(EGL "egl" "EGL" ) -ff_lib_enable(GLX - "glx" - "GLX" -) +if(NOT OpenBSD) + ff_lib_enable(GLX + "glx" + "GLX" + ) +else() + ff_lib_enable(GLX + "gl" + "GL" + ) +endif() ff_lib_enable(OSMESA "osmesa" "OSMesa" @@ -1194,7 +1301,6 @@ elseif(APPLE) PRIVATE "-weak_framework Apple80211" ) elseif(WIN32) - target_compile_definitions(libfastfetch PRIVATE -D_WIN32_WINNT=0x0A00) target_link_libraries(libfastfetch PRIVATE "dwmapi" PRIVATE "gdi32" @@ -1208,6 +1314,7 @@ elseif(WIN32) PRIVATE "hid" PRIVATE "wtsapi32" PRIVATE "imagehlp" + PRIVATE "cfgmgr32" ) elseif(FreeBSD) target_link_libraries(libfastfetch @@ -1215,6 +1322,11 @@ elseif(FreeBSD) PRIVATE "usbhid" PRIVATE "geom" ) +elseif(OpenBSD) + target_link_libraries(libfastfetch + PRIVATE "m" + PRIVATE "kvm" + ) elseif(SunOS) target_link_libraries(libfastfetch PRIVATE "m" @@ -1290,6 +1402,10 @@ if(NOT WIN32) if(HAVE_WORDEXP) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WORDEXP=1) endif() + CHECK_INCLUDE_FILE("glob.h" HAVE_GLOB) + if(HAVE_GLOB) + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_GLOB=1) + endif() if(ENABLE_THREADS AND CMAKE_USE_PTHREADS_INIT) CHECK_INCLUDE_FILE("pthread_np.h" HAVE_PTHREAD_NP) if(HAVE_PTHREAD_NP) diff --git a/completions/fastfetch.bash b/completions/fastfetch.bash index 76e43859a7..0e7464d6b7 100644 --- a/completions/fastfetch.bash +++ b/completions/fastfetch.bash @@ -183,7 +183,10 @@ __fastfetch_completion() "--display-precise-refresh-rate" "--localip-show-ipv4" "--localip-show-ipv6" + "--localip-show-flags" "--localip-show-loop" + "--localip-show-mtu" + "--localip-show-speed" "--localip-name-prefix" "--localip-compact-type" "--escape-bedrock" diff --git a/debian/changelog b/debian/changelog index 3eff4467a1..42685d71b8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +fastfetch (2.27.1) jammy; urgency=medium + + * Update to 2.27.1 + + -- Carter Li Sun, 06 Oct 2024 12:55:18 +0800 + fastfetch (2.26.1ubuntu1) jammy; urgency=medium * Update correct code diff --git a/debian/files b/debian/files index 8a4ba4133c..a5daf6ddf5 100644 --- a/debian/files +++ b/debian/files @@ -1 +1 @@ -fastfetch_2.26.1ubuntu1_source.buildinfo universe/utils optional +fastfetch_2.27.1_source.buildinfo universe/utils optional diff --git a/doc/json_schema.json b/doc/json_schema.json index 009e35484a..c9bf608317 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -344,7 +344,7 @@ "description": "Set the command to be executed before printing logos", "default": "" }, - "showVersion": { + "detectVersion": { "type": "boolean", "description": "Whether to detect and display component versions. Mainly for benchmarking", "default": true @@ -816,7 +816,7 @@ }, { "const": "monitor", - "description": "Alias of Display module; deprecated" + "description": "Alias of Display module" }, { "const": "opencl", @@ -1703,6 +1703,11 @@ "type": "boolean", "default": false }, + "showFlags": { + "description": "Show the interface's flags", + "type": "boolean", + "default": false + }, "compact": { "description": "Show all IPs in one line", "type": "boolean", diff --git a/presets/all.jsonc b/presets/all.jsonc index 9b27615e04..8e4da85d62 100644 --- a/presets/all.jsonc +++ b/presets/all.jsonc @@ -72,7 +72,9 @@ "showIpv6": true, "showMac": true, "showSpeed": true, - "showMtu": true + "showMtu": true, + "showLoop": true, + "showFlags": true }, "dns", "wifi", diff --git a/presets/ci.jsonc b/presets/ci.jsonc index 3027010d8f..6431509c28 100644 --- a/presets/ci.jsonc +++ b/presets/ci.jsonc @@ -74,7 +74,9 @@ "showIpv6": true, "showMac": true, "showSpeed": true, - "showMtu": true + "showMtu": true, + "showLoop": true, + "showFlags": true }, "dns", "wifi", diff --git a/run.sh b/run.sh index aebcfc9d9c..55071e4003 100755 --- a/run.sh +++ b/run.sh @@ -5,18 +5,22 @@ set -e mkdir -p build/ cd build/ -if [ -z "${CMAKE_BUILD_TYPE}" ]; then - CMAKE_BUILD_TYPE=Release -fi -cmake "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" .. +cmake .. -if [ -z "$OSTYPE" ] || [ "$OSTYPE" = "linux-gnu" ]; then - cmake_build_args="-j$(nproc)" -elif [ "$OSTYPE" = "darwin" ]; then - cmake_build_args="-j$(sysctl -n hw.ncpu)" -else - cmake_build_args="" -fi -cmake --build . --target fastfetch ${cmake_build_args} +kernel_name="$(uname -s)" + +case "${kernel_name}" in + "Linux" | "MINGW"*) + cmake_build_args="-j$(nproc)" + ;; + "Darwin" | *"BSD" | "DragonFly") + cmake_build_args="-j$(sysctl -n hw.ncpu)" + ;; + *) + cmake_build_args="" + ;; +esac + +cmake --build . --target fastfetch "${cmake_build_args}" ./fastfetch "$@" diff --git a/src/common/init.c b/src/common/init.c index 514b9fb6af..643f94a944 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -245,7 +245,7 @@ void ffListFeatures(void) #if FF_HAVE_DDCUTIL "libddcutil\n" #endif - #if FF_HAVE_ELF || __sun || __FreeBSD__ + #if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__ "libelf\n" #endif #if FF_HAVE_LIBZFS diff --git a/src/common/io/io.h b/src/common/io/io.h index 9a76838f4f..9081699854 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -66,9 +66,11 @@ static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) } ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data); +ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileName, size_t dataSize, void* data); bool ffAppendFDBuffer(FFNativeFD fd, FFstrbuf* buffer); bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer); +bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer); static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) { @@ -76,6 +78,12 @@ static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) return ffAppendFileBuffer(fileName, buffer); } +static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) +{ + ffStrbufClear(buffer); + return ffAppendFileBufferRelative(dfd, fileName, buffer); +} + //Bit flags, combine with | typedef enum FFPathType { @@ -211,3 +219,8 @@ static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* return false; } + +#ifdef _WIN32 +// Only O_RDONLY is supported +HANDLE openat(HANDLE dfd, const char* fileName, bool directory); +#endif diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index facc03a56f..a1a0ccd652 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -14,8 +14,11 @@ #if FF_HAVE_WORDEXP #include +#elif FF_HAVE_GLOB + #warning " is not available, use instead" + #include #else - #warning " not available" + #warning "Neither nor is available" #endif static void createSubfolders(const char* fileName) @@ -105,6 +108,15 @@ ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data) return ffReadFDData(fd, dataSize, data); } +ssize_t ffReadFileDataRelative(int dfd, const char* fileName, size_t dataSize, void* data) +{ + int FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC); + if(fd == -1) + return -1; + + return ffReadFDData(fd, dataSize, data); +} + bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) { int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY | O_CLOEXEC); @@ -114,6 +126,15 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) return ffAppendFDBuffer(fd, buffer); } +bool ffAppendFileBufferRelative(int dfd, const char* fileName, FFstrbuf* buffer) +{ + int FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC); + if(fd == -1) + return false; + + return ffAppendFDBuffer(fd, buffer); +} + bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out) { bool result = false; @@ -121,7 +142,7 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o #if FF_HAVE_WORDEXP // https://github.com/termux/termux-packages/pull/7056 wordexp_t exp; - if(wordexp(in, &exp, 0) != 0) + if (wordexp(in, &exp, 0) != 0) return false; if (exp.we_wordc == 1) @@ -132,6 +153,20 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o wordfree(&exp); + #elif FF_HAVE_GLOB + + glob_t gb; + if (glob(in, GLOB_NOSORT | GLOB_TILDE, NULL, &gb) != 0) + return false; + + if (gb.gl_matchc == 1) + { + result = true; + ffStrbufSetS(out, gb.gl_pathv[0]); + } + + globfree(&gb); + #endif return result; @@ -191,14 +226,24 @@ const char* ffGetTerminalResponse(const char* request, int nParams, const char* ssize_t nRead = read(ftty, buffer + bytesRead, sizeof(buffer) - bytesRead - 1); if (nRead <= 0) + { + va_end(args); return "read(STDIN_FILENO, buffer, sizeof(buffer) - 1) failed"; + } bytesRead += (size_t) nRead; buffer[bytesRead] = '\0'; - int ret = vsscanf(buffer, format, args); + va_list cargs; + va_copy(cargs, args); + int ret = vsscanf(buffer, format, cargs); + va_end(cargs); + if (ret <= 0) + { + va_end(args); return "vsscanf(buffer, format, args) failed"; + } if (ret >= nParams) break; } diff --git a/src/common/io/io_windows.c b/src/common/io/io_windows.c index 6f2465da64..9f1a96ce53 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -3,6 +3,8 @@ #include "util/stringUtils.h" #include +#include +#include static void createSubfolders(const char* fileName) { @@ -38,7 +40,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) static inline void readWithLength(HANDLE handle, FFstrbuf* buffer, uint32_t length) { - ffStrbufEnsureFixedLengthFree(buffer, length); + ffStrbufEnsureFree(buffer, length); DWORD bytesRead = 0; while( length > 0 && @@ -100,6 +102,49 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) return ffAppendFDBuffer(handle, buffer); } +HANDLE openat(HANDLE dfd, const char* fileName, bool directory) +{ + NTSTATUS ret; + UNICODE_STRING fileNameW; + ret = RtlAnsiStringToUnicodeString(&fileNameW, &(ANSI_STRING) { + .Length = (USHORT) strlen(fileName), + .Buffer = (PCHAR) fileName + }, TRUE); + if (!NT_SUCCESS(ret)) return INVALID_HANDLE_VALUE; + + FF_AUTO_CLOSE_FD HANDLE hFile; + IO_STATUS_BLOCK iosb = {}; + ret = NtOpenFile(&hFile, FILE_READ_DATA | SYNCHRONIZE, &(OBJECT_ATTRIBUTES) { + .Length = sizeof(OBJECT_ATTRIBUTES), + .RootDirectory = dfd, + .ObjectName = &fileNameW, + }, &iosb, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT | (directory ? FILE_DIRECTORY_FILE : FILE_NON_DIRECTORY_FILE)); + RtlFreeUnicodeString(&fileNameW); + + if(!NT_SUCCESS(ret) || iosb.Information != FILE_OPENED) + return INVALID_HANDLE_VALUE; + + return hFile; +} + +bool ffAppendFileBufferRelative(HANDLE dfd, const char* fileName, FFstrbuf* buffer) +{ + HANDLE FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, false); + if(fd == INVALID_HANDLE_VALUE) + return false; + + return ffAppendFDBuffer(fd, buffer); +} + +ssize_t ffReadFileDataRelative(HANDLE dfd, const char* fileName, size_t dataSize, void* data) +{ + HANDLE FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, false); + if(fd == INVALID_HANDLE_VALUE) + return -1; + + return ffReadFDData(fd, dataSize, data); +} + bool ffPathExpandEnv(const char* in, FFstrbuf* out) { DWORD length = ExpandEnvironmentStringsA(in, NULL, 0); @@ -266,14 +311,24 @@ const char* ffGetTerminalResponse(const char* request, int nParams, const char* { DWORD bytes = 0; if (!ReadFile(hInput, buffer, sizeof(buffer) - 1, &bytes, NULL) || bytes == 0) + { + va_end(args); return "ReadFile() failed"; + } bytesRead += bytes; buffer[bytesRead] = '\0'; + va_list cargs; + va_copy(cargs, args); int ret = vsscanf(buffer, format, args); + va_end(cargs); + if (ret <= 0) + { + va_end(args); return "vsscanf(buffer, format, args) failed"; + } if (ret >= nParams) break; } diff --git a/src/common/modules.c b/src/common/modules.c index 4e8ae69e4c..ce649cfc93 100644 --- a/src/common/modules.c +++ b/src/common/modules.c @@ -73,6 +73,7 @@ static FFModuleBaseInfo* J[] = { static FFModuleBaseInfo* K[] = { (void*) &instance.config.modules.kernel, + (void*) &instance.config.modules.keyboard, NULL, }; @@ -88,6 +89,7 @@ static FFModuleBaseInfo* M[] = { (void*) &instance.config.modules.media, (void*) &instance.config.modules.memory, (void*) &instance.config.modules.monitor, + (void*) &instance.config.modules.mouse, NULL, }; diff --git a/src/common/netif/netif_linux.c b/src/common/netif/netif_linux.c index f645b0a0b7..1845ee0e2e 100644 --- a/src/common/netif/netif_linux.c +++ b/src/common/netif/netif_linux.c @@ -13,11 +13,9 @@ bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex) if (!netRoute) return false; // skip first line - flockfile(netRoute); - while (getc_unlocked(netRoute) != '\n'); - funlockfile(netRoute); - unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu, + FF_UNUSED(fscanf(netRoute, "%*[^\n]\n")); + unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu, while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", iface, &destination) == 2) { if (destination != 0) continue; diff --git a/src/common/parsing.c b/src/common/parsing.c index ec58f9fa21..50f1a54aac 100644 --- a/src/common/parsing.c +++ b/src/common/parsing.c @@ -190,6 +190,48 @@ void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, co } } +void ffParseDuration(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds, FFstrbuf* result) +{ + if(days == 0 && hours == 0 && minutes == 0) + { + ffStrbufAppendF(result, "%u seconds", seconds); + return; + } + + if(days > 0) + { + ffStrbufAppendF(result, "%u day", days); + + if(days > 1) + ffStrbufAppendC(result, 's'); + + if(days >= 100) + ffStrbufAppendS(result, "(!)"); + + if(hours > 0 || minutes > 0) + ffStrbufAppendS(result, ", "); + } + + if(hours > 0) + { + ffStrbufAppendF(result, "%u hour", hours); + + if(hours > 1) + ffStrbufAppendC(result, 's'); + + if(minutes > 0) + ffStrbufAppendS(result, ", "); + } + + if(minutes > 0) + { + ffStrbufAppendF(result, "%u min", minutes); + + if(minutes > 1) + ffStrbufAppendC(result, 's'); + } +} + #ifdef _WIN32 #pragma GCC diagnostic pop #endif diff --git a/src/common/parsing.h b/src/common/parsing.h index 722969ffb2..bc04cf2f04 100644 --- a/src/common/parsing.h +++ b/src/common/parsing.h @@ -27,3 +27,4 @@ int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2); void ffParseSize(uint64_t bytes, FFstrbuf* result); bool ffParseFrequency(uint32_t mhz, FFstrbuf* result); +void ffParseDuration(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds, FFstrbuf* result); diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index af3f4ebf50..c7c7cd556e 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -22,6 +22,10 @@ #include #elif defined(__sun) #include +#elif defined(__OpenBSD__) +#include +#include +#include #endif enum { FF_PIPE_BUFSIZ = 8192 }; @@ -135,12 +139,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons if (exePath) { snprintf(filePath, sizeof(filePath), "/proc/%d/exe", (int)pid); - ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX); - ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1); + char buf[PATH_MAX]; + ssize_t length = readlink(filePath, buf, PATH_MAX - 1); if (length > 0) // doesn't contain trailing NUL { - exePath->chars[length] = '\0'; - exePath->length = (uint32_t) length; + buf[length] = '\0'; + ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL + ffStrbufAppendNS(exePath, (uint32_t)length, buf); } } @@ -238,7 +243,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons #elif defined(__sun) - char filePath[PATH_MAX]; + char filePath[128]; snprintf(filePath, sizeof(filePath), "/proc/%d/psinfo", (int) pid); psinfo_t proc; if (ffReadFileData(filePath, sizeof(proc), &proc) == sizeof(proc)) @@ -250,15 +255,28 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons if (exePath) { snprintf(filePath, sizeof(filePath), "/proc/%d/path/a.out", (int) pid); - ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX); - ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1); + char buf[PATH_MAX]; + ssize_t length = readlink(filePath, buf, PATH_MAX - 1); if (length > 0) // doesn't contain trailing NUL { - exePath->chars[length] = '\0'; - exePath->length = (uint32_t) length; + buf[length] = '\0'; + ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length + 1); // +1 for the NUL + ffStrbufAppendNS(exePath, (uint32_t)length, buf); } } + #elif defined(__OpenBSD__) + + kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL); + int count = 0; + const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count); + if (proc) + { + char** argv = kvm_getargv(kd, proc, 0); + if (argv) ffStrbufSetS(exe, argv[0]); + } + kvm_close(kd); + #endif if(exe->length == 0) @@ -373,6 +391,23 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i if (tty) *tty = (int) proc.pr_ttydev; + #elif defined(__OpenBSD__) + + kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL); + int count = 0; + const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count); + if (proc) + { + ffStrbufSetS(name, proc->p_comm); + if (ppid) + *ppid = proc->p_ppid; + if (tty) + *tty = (int) proc->p_tdev; + } + kvm_close(kd); + if (!proc) + return "kvm_getprocs() failed"; + #else return "Unsupported platform"; diff --git a/src/common/sysctl.c b/src/common/sysctl.c index 4f0f3b65ce..42a5875a6a 100644 --- a/src/common/sysctl.c +++ b/src/common/sysctl.c @@ -2,6 +2,41 @@ #include +#ifdef __OpenBSD__ +const char* ffSysctlGetString(int mib1, int mib2, FFstrbuf* result) +{ + size_t neededLength; + if (sysctl((int[]) {mib1, mib2}, 2, NULL, &neededLength, NULL, 0) != 0 || neededLength == 1) //neededLength is 1 for empty strings, because of the null terminator + return "sysctlbyname() failed"; + + ffStrbufEnsureFree(result, (uint32_t) neededLength - 1); + + if (sysctl((int[]) {mib1, mib2}, 2, result->chars + result->length, &neededLength, NULL, 0) == 0) + result->length += (uint32_t) neededLength - 1; + + result->chars[result->length] = '\0'; + + return NULL; +} + +int ffSysctlGetInt(int mib1, int mib2, int defaultValue) +{ + int result; + size_t neededLength = sizeof(result); + if (sysctl((int[]) {mib1, mib2}, 2, &result, &neededLength, NULL, 0) != 0) + return defaultValue; + return result; +} + +int64_t ffSysctlGetInt64(int mib1, int mib2, int64_t defaultValue) +{ + int64_t result; + size_t neededLength = sizeof(result); + if(sysctl((int[]) {mib1, mib2}, 2, &result, &neededLength, NULL, 0) != 0) + return defaultValue; + return result; +} +#else const char* ffSysctlGetString(const char* propName, FFstrbuf* result) { size_t neededLength; @@ -35,6 +70,7 @@ int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue) return defaultValue; return result; } +#endif // OpenBSD void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength) { diff --git a/src/common/sysctl.h b/src/common/sysctl.h index 2a210de862..1d5cc503a6 100644 --- a/src/common/sysctl.h +++ b/src/common/sysctl.h @@ -6,7 +6,13 @@ #include #include +#ifdef __OpenBSD__ +const char* ffSysctlGetString(int mib1, int mib2, FFstrbuf* result); +FF_C_NODISCARD int ffSysctlGetInt(int mib1, int mib2, int defaultValue); +FF_C_NODISCARD int64_t ffSysctlGetInt64(int mib1, int mib2, int64_t defaultValue); +#else const char* ffSysctlGetString(const char* propName, FFstrbuf* result); FF_C_NODISCARD int ffSysctlGetInt(const char* propName, int defaultValue); FF_C_NODISCARD int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue); +#endif FF_C_NODISCARD void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength); diff --git a/src/data/help.json b/src/data/help.json index 2d99a0b3aa..bdce5411fe 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1196,6 +1196,24 @@ "default": false } }, + { + "long": "localip-show-mtu", + "desc": "Show net interface's MTU (Maximum Transmission Unit) size in bytes", + "arg": { + "type": "bool", + "optional": true, + "default": false + } + }, + { + "long": "localip-show-speed", + "desc": "Show net interface's link speed with human-readable format (or an 1Mb units integer in JSON format)", + "arg": { + "type": "bool", + "optional": true, + "default": false + } + }, { "long": "localip-show-prefix-len", "desc": "Show network prefix length (/N) in local ip module", @@ -1231,6 +1249,15 @@ "default": false } }, + { + "long": "localip-show-flags", + "desc": "Show net interface flags in local ip module", + "arg": { + "type": "bool", + "optional": true, + "default": false + } + }, { "long": "localip-compact", "desc": "Show all IPs in one line", diff --git a/src/detection/battery/battery.h b/src/detection/battery/battery.h index 2f4c8e3f17..d31a7ef71d 100644 --- a/src/detection/battery/battery.h +++ b/src/detection/battery/battery.h @@ -15,6 +15,7 @@ typedef struct FFBatteryResult double capacity; double temperature; uint32_t cycleCount; + int32_t timeRemaining; } FFBatteryResult; const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results); diff --git a/src/detection/battery/battery_android.c b/src/detection/battery/battery_android.c index 6a5e807eaf..da2cb8f211 100644 --- a/src/detection/battery/battery_android.c +++ b/src/detection/battery/battery_android.c @@ -1,6 +1,6 @@ #include "fastfetch.h" #include "battery.h" - +#include "util/stringUtils.h" #include "common/processing.h" #include "common/properties.h" @@ -36,6 +36,7 @@ static const char* parseTermuxApi(FFBatteryOptions* options, FFlist* results) FFBatteryResult* battery = ffListAdd(results); battery->temperature = FF_BATTERY_TEMP_UNSET; battery->cycleCount = 0; + battery->timeRemaining = -1; ffStrbufInit(&battery->manufacturer); ffStrbufInit(&battery->modelName); ffStrbufInit(&battery->status); @@ -44,7 +45,27 @@ static const char* parseTermuxApi(FFBatteryOptions* options, FFlist* results) ffStrbufInit(&battery->manufactureDate); battery->capacity = yyjson_get_num(yyjson_obj_get(root, "percentage")); - ffStrbufAppendS(&battery->status, yyjson_get_str(yyjson_obj_get(root, "status"))); + const char* acStatus = yyjson_get_str(yyjson_obj_get(root, "plugged")); + if (acStatus) + { + if (ffStrEquals(acStatus, "PLUGGED_AC")) + ffStrbufAppendS(&battery->status, "AC Connected, "); + else if (ffStrEquals(acStatus, "PLUGGED_USB")) + ffStrbufAppendS(&battery->status, "USB Connected, "); + else if (ffStrEquals(acStatus, "PLUGGED_WIRELESS")) + ffStrbufAppendS(&battery->status, "Wireless Connected, "); + } + const char* status = yyjson_get_str(yyjson_obj_get(root, "status")); + if (status) + { + if (ffStrEquals(status, "CHARGING")) + ffStrbufAppendS(&battery->status, "Charging"); + else if (ffStrEquals(status, "DISCHARGING")) + ffStrbufAppendS(&battery->status, "Discharging"); + } + ffStrbufTrimRight(&battery->status, ' '); + ffStrbufTrimRight(&battery->status, ','); + if(options->temp) battery->temperature = yyjson_get_num(yyjson_obj_get(root, "temperature")); @@ -74,6 +95,7 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results) FFBatteryResult* battery = ffListAdd(results); battery->temperature = FF_BATTERY_TEMP_UNSET; battery->cycleCount = 0; + battery->timeRemaining = -1; ffStrbufInit(&battery->manufacturer); ffStrbufInit(&battery->modelName); ffStrbufInit(&battery->status); diff --git a/src/detection/battery/battery_apple.c b/src/detection/battery/battery_apple.c index 4f3d809b67..ec90f1e79e 100644 --- a/src/detection/battery/battery_apple.c +++ b/src/detection/battery/battery_apple.c @@ -60,7 +60,14 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) && boolValue) ffStrbufAppendS(&battery->status, "AC connected, "); else + { ffStrbufAppendS(&battery->status, "Discharging, "); + ffCfDictGetInt(properties, CFSTR(kIOPMPSTimeRemainingKey), &battery->timeRemaining); // in minutes + if (battery->timeRemaining == 0xFFFF) + battery->timeRemaining = -1; + else + battery->timeRemaining *= 60; + } if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) && boolValue) ffStrbufAppendS(&battery->status, "Charging, "); if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) && boolValue) diff --git a/src/detection/battery/battery_bsd.c b/src/detection/battery/battery_bsd.c index 76b057a74a..228d6aa362 100644 --- a/src/detection/battery/battery_bsd.c +++ b/src/detection/battery/battery_bsd.c @@ -41,7 +41,9 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r ffStrbufInit(&battery->technology); ffStrbufInit(&battery->serial); ffStrbufInit(&battery->manufactureDate); - + battery->timeRemaining = -1; + if (battio.battinfo.min > 0) + battery->timeRemaining = battio.battinfo.min * 60; battery->capacity = battio.battinfo.cap; if(battio.battinfo.state == ACPI_BATT_STAT_INVALID) { @@ -74,6 +76,7 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r ffStrbufAppendS(&battery->manufacturer, battio.bix.oeminfo); ffStrbufAppendS(&battery->modelName, battio.bix.model); ffStrbufAppendS(&battery->technology, battio.bix.type); + battery->cycleCount = battio.bix.cycles; } } return NULL; diff --git a/src/detection/battery/battery_linux.c b/src/detection/battery/battery_linux.c index 0d76871c5d..71ea2480a5 100644 --- a/src/detection/battery/battery_linux.c +++ b/src/detection/battery/battery_linux.c @@ -3,39 +3,45 @@ #include "util/stringUtils.h" #include +#include +#include // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power -static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* options, FFlist* results) +static bool checkAc(const char* id, FFstrbuf* tmpBuffer) { - uint32_t dirLength = dir->length; + if (ffStrStartsWith(id, "BAT")) + ffStrbufSetS(tmpBuffer, "/sys/class/power_supply/ADP1/online"); + else if (ffStrStartsWith(id, "macsmc-battery")) + ffStrbufSetS(tmpBuffer, "/sys/class/power_supply/macsmc-ac/online"); + else + ffStrbufClear(tmpBuffer); + + char online = '\0'; + return ffReadFileData(tmpBuffer->chars, 1, &online) == 1 && online == '1'; +} +static void parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFlist* results) +{ FF_STRBUF_AUTO_DESTROY tmpBuffer = ffStrbufCreate(); - //type must exist and be "Battery" - ffStrbufAppendS(dir, "/type"); - if (ffReadFileBuffer(dir->chars, &tmpBuffer)) - ffStrbufTrimRightSpace(&tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); - + // type must exist and be "Battery" + if (!ffReadFileBufferRelative(dfd, "type", &tmpBuffer)) + return; + ffStrbufTrimRightSpace(&tmpBuffer); if(!ffStrbufIgnCaseEqualS(&tmpBuffer, "Battery")) return; - //scope may not exist or must not be "Device" - ffStrbufAppendS(dir, "/scope"); - if (ffReadFileBuffer(dir->chars, &tmpBuffer)) + // scope may not exist or must not be "Device" + if (ffReadFileBufferRelative(dfd, "scope", &tmpBuffer)) ffStrbufTrimRightSpace(&tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseEqualS(&tmpBuffer, "Device")) return; - //capacity must exist and be not empty - ffStrbufAppendS(dir, "/capacity"); - bool available = ffReadFileBuffer(dir->chars, &tmpBuffer); // This is expensive in my laptop - ffStrbufSubstrBefore(dir, dirLength); - - if (!available) + // capacity must exist and be not empty + // This is expensive in my laptop + if (!ffReadFileBufferRelative(dfd, "capacity", &tmpBuffer)) return; FFBatteryResult* result = ffListAdd(results); @@ -44,39 +50,63 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option //At this point, we have a battery. Try to get as much values as possible. ffStrbufInit(&result->manufacturer); - ffStrbufAppendS(dir, "/manufacturer"); - if (ffReadFileBuffer(dir->chars, &result->manufacturer)) + if (ffReadFileBufferRelative(dfd, "manufacturer", &result->manufacturer)) ffStrbufTrimRightSpace(&result->manufacturer); else if (ffStrEquals(id, "macsmc-battery")) // asahi ffStrbufSetStatic(&result->manufacturer, "Apple Inc."); - ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->modelName); - ffStrbufAppendS(dir, "/model_name"); - if (ffReadFileBuffer(dir->chars, &result->modelName)) + if (ffReadFileBufferRelative(dfd, "model_name", &result->modelName)) ffStrbufTrimRightSpace(&result->modelName); - ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->technology); - ffStrbufAppendS(dir, "/technology"); - if (ffReadFileBuffer(dir->chars, &result->technology)) + if (ffReadFileBufferRelative(dfd, "technology", &result->technology)) ffStrbufTrimRightSpace(&result->technology); - ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->status); - ffStrbufAppendS(dir, "/status"); - if (ffReadFileBuffer(dir->chars, &result->status)) + if (ffReadFileBufferRelative(dfd, "status", &result->status)) ffStrbufTrimRightSpace(&result->status); - ffStrbufSubstrBefore(dir, dirLength); // Unknown, Charging, Discharging, Not charging, Full - if (ffStrbufEqualS(&result->status, "Not charging") || ffStrbufEqualS(&result->status, "Full")) + + result->timeRemaining = -1; + if (ffStrbufEqualS(&result->status, "Discharging")) + { + if (ffReadFileBufferRelative(dfd, "time_to_empty_now", &tmpBuffer)) + result->timeRemaining = (int32_t) ffStrbufToSInt(&tmpBuffer, 0); + else + { + if (ffReadFileBufferRelative(dfd, "charge_now", &tmpBuffer)) + { + int64_t chargeNow = ffStrbufToSInt(&tmpBuffer, 0); + if (chargeNow > 0) + { + if (ffReadFileBufferRelative(dfd, "current_now", &tmpBuffer)) + { + int64_t currentNow = ffStrbufToSInt(&tmpBuffer, INT64_MIN); + if (currentNow < 0) currentNow = -currentNow; + if (currentNow > 0) + result->timeRemaining = (int32_t) ((chargeNow * 3600) / currentNow); + } + } + } + } + + if (checkAc(id, &tmpBuffer)) + ffStrbufAppendS(&result->status, ", AC Connected"); + } + else if (ffStrbufEqualS(&result->status, "Not charging") || ffStrbufEqualS(&result->status, "Full")) ffStrbufSetStatic(&result->status, "AC Connected"); + else if (ffStrbufEqualS(&result->status, "Charging")) + ffStrbufAppendS(&result->status, ", AC Connected"); else if (ffStrbufEqualS(&result->status, "Unknown")) + { ffStrbufClear(&result->status); + if (checkAc(id, &tmpBuffer)) + ffStrbufAppendS(&result->status, "AC Connected"); + } - ffStrbufAppendS(dir, "/capacity_level"); - if (ffReadFileBuffer(dir->chars, &tmpBuffer)) + if (ffReadFileBufferRelative(dfd, "capacity_level", &tmpBuffer)) { ffStrbufTrimRightSpace(&result->manufacturer); if (ffStrbufEqualS(&tmpBuffer, "Critical")) @@ -87,50 +117,33 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option ffStrbufSetStatic(&result->status, "Critical"); } } - ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->serial); - ffStrbufAppendS(dir, "/serial_number"); - if (ffReadFileBuffer(dir->chars, &result->serial)) + if (ffReadFileBufferRelative(dfd, "serial_number", &result->serial)) ffStrbufTrimRightSpace(&result->serial); - ffStrbufSubstrBefore(dir, dirLength); - ffStrbufAppendS(dir, "/cycle_count"); - available = ffReadFileBuffer(dir->chars, &tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); - if (available) + if (ffReadFileBufferRelative(dfd, "cycle_count", &tmpBuffer)) { int64_t cycleCount = ffStrbufToSInt(&tmpBuffer, 0); result->cycleCount = cycleCount < 0 || cycleCount > UINT32_MAX ? 0 : (uint32_t) cycleCount; } ffStrbufInit(&result->manufactureDate); - ffStrbufAppendS(dir, "/manufacture_year"); - available = ffReadFileBuffer(dir->chars, &tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); - if (available) + if (ffReadFileBufferRelative(dfd, "manufacture_year", &tmpBuffer)) { int year = (int) ffStrbufToSInt(&tmpBuffer, 0); if (year > 0) { - ffStrbufAppendS(dir, "/manufacture_month"); - available = ffReadFileBuffer(dir->chars, &tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); - if (available) + if (ffReadFileBufferRelative(dfd, "manufacture_month", &tmpBuffer)) { int month = (int) ffStrbufToSInt(&tmpBuffer, 0); if (month > 0) { - ffStrbufAppendS(dir, "/manufacture_day"); - available = ffReadFileBuffer(dir->chars, &tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); - if (available) + if (ffReadFileBufferRelative(dfd, "manufacture_day", &tmpBuffer)) { int day = (int) ffStrbufToSInt(&tmpBuffer, 0); if (day > 0) - { ffStrbufSetF(&result->manufactureDate, "%.4d-%.2d-%.2d", year, month, day); - } } } } @@ -140,21 +153,14 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option result->temperature = FF_BATTERY_TEMP_UNSET; if (options->temp) { - ffStrbufAppendS(dir, "/temp"); - if (ffReadFileBuffer(dir->chars, &tmpBuffer)) + if (ffReadFileBufferRelative(dfd, "temp", &tmpBuffer)) result->temperature = ffStrbufToDouble(&tmpBuffer) / 10; - ffStrbufSubstrBefore(dir, dirLength); } } const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) { - FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64); - ffStrbufAppendS(&baseDir, "/sys/class/power_supply/"); - - uint32_t baseDirLength = baseDir.length; - - FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir.chars); + FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/power_supply/"); if(dirp == NULL) return "opendir(\"/sys/class/power_supply/\") == NULL"; @@ -164,9 +170,8 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, "..")) continue; - ffStrbufAppendS(&baseDir, entry->d_name); - parseBattery(&baseDir, entry->d_name, options, results); - ffStrbufSubstrBefore(&baseDir, baseDirLength); + FF_AUTO_CLOSE_FD int dfd = openat(dirfd(dirp), entry->d_name, O_RDONLY | O_CLOEXEC); + if (dfd > 0) parseBattery(dfd, entry->d_name, options, results); } return NULL; diff --git a/src/detection/battery/battery_windows.c b/src/detection/battery/battery_windows.c index 6c72982318..101bd6dea7 100644 --- a/src/detection/battery/battery_windows.c +++ b/src/detection/battery/battery_windows.c @@ -121,6 +121,13 @@ static const char* detectWithSetupApi(FFBatteryOptions* options, FFlist* results battery->temperature = temp / 10.0 - 273.15; } + { + bqi.InformationLevel = BatteryEstimatedTime; + ULONG time; + if(DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), &time, sizeof(time), &dwOut, NULL)) + battery->timeRemaining = time == BATTERY_UNKNOWN_TIME ? -1 : (int32_t) time; + } + { BATTERY_STATUS bs; BATTERY_WAIT_STATUS bws = { .BatteryTag = bqi.BatteryTag }; @@ -241,6 +248,7 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF ffStrbufInit(&battery->serial); battery->temperature = FF_BATTERY_TEMP_UNSET; battery->cycleCount = 0; + battery->timeRemaining = info.EstimatedTime == BATTERY_UNKNOWN_TIME ? -1 : (int32_t) info.EstimatedTime; battery->capacity = info.RemainingCapacity * 100.0 / info.MaxCapacity; if(info.AcOnLine) @@ -252,6 +260,7 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF else if(info.Discharging) ffStrbufAppendS(&battery->status, "Discharging"); + detectBySmbios(battery); return NULL; diff --git a/src/detection/bios/bios_nosupport.c b/src/detection/bios/bios_nosupport.c index 76abc7a12b..ac544fd3e0 100644 --- a/src/detection/bios/bios_nosupport.c +++ b/src/detection/bios/bios_nosupport.c @@ -1,6 +1,6 @@ #include "bios.h" -const char* ffDetectBios(FFBiosResult* bios) +const char* ffDetectBios(FF_MAYBE_UNUSED FFBiosResult* bios) { return "Not supported on this platform"; } diff --git a/src/detection/bluetoothradio/bluetoothradio_linux.c b/src/detection/bluetoothradio/bluetoothradio_linux.c index 6157ee16bd..05b77523cc 100644 --- a/src/detection/bluetoothradio/bluetoothradio_linux.c +++ b/src/detection/bluetoothradio/bluetoothradio_linux.c @@ -202,6 +202,7 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */) #ifdef FF_HAVE_DBUS return detectBluetooth(devices); #else + FF_UNUSED(devices) return "Fastfetch was compiled without DBus support"; #endif } diff --git a/src/detection/board/board_linux.c b/src/detection/board/board_linux.c index 2820bbc847..70cd54034a 100644 --- a/src/detection/board/board_linux.c +++ b/src/detection/board/board_linux.c @@ -12,13 +12,17 @@ const char* ffDetectBoard(FFBoardResult* board) ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_vendor", "/sys/class/dmi/id/board_vendor", &board->vendor); ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_version", "/sys/class/dmi/id/board_version", &board->version); } - else if (ffReadFileBuffer("/proc/device-tree/board", &board->vendor) || - ffReadFileBuffer("/proc/device-tree/compatible", &board->vendor)) + else if (ffReadFileBuffer("/proc/device-tree/board", &board->name)) + { + ffStrbufTrimRightSpace(&board->name); + } + else if (ffReadFileBuffer("/proc/device-tree/compatible", &board->vendor)) { uint32_t comma = ffStrbufFirstIndexC(&board->vendor, ','); if (comma < board->vendor.length) { ffStrbufSetS(&board->name, board->vendor.chars + comma + 1); + ffStrbufTrimRightSpace(&board->name); ffStrbufSubstrBefore(&board->vendor, comma); } } diff --git a/src/detection/cpu/cpu_nosupport.c b/src/detection/cpu/cpu_nosupport.c index 2a06915d28..49e125b5a4 100644 --- a/src/detection/cpu/cpu_nosupport.c +++ b/src/detection/cpu/cpu_nosupport.c @@ -1,6 +1,6 @@ #include "cpu.h" -const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) +const char* ffDetectCPUImpl(FF_MAYBE_UNUSED const FFCPUOptions* options, FF_MAYBE_UNUSED FFCPUResult* cpu) { return "Not supported on this platform"; } diff --git a/src/detection/cpu/cpu_obsd.c b/src/detection/cpu/cpu_obsd.c new file mode 100644 index 0000000000..04d5501989 --- /dev/null +++ b/src/detection/cpu/cpu_obsd.c @@ -0,0 +1,19 @@ +#include "cpu.h" +#include "common/sysctl.h" + +const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) +{ + if (ffSysctlGetString(CTL_HW, HW_MODEL, &cpu->name)) + return "sysctl(hw.model) failed"; + + cpu->coresPhysical = (uint16_t) ffSysctlGetInt(CTL_HW, HW_NCPU, 1); + cpu->coresLogical = cpu->coresPhysical; + cpu->coresOnline = (uint16_t) ffSysctlGetInt(CTL_HW, HW_NCPUONLINE, cpu->coresLogical); + + ffCPUDetectSpeedByCpuid(cpu); + + cpu->frequencyBase = (uint32_t) ffSysctlGetInt(CTL_HW, HW_CPUSPEED, 0); + cpu->temperature = FF_CPU_TEMP_UNSET; // HW_SENSORS? + + return NULL; +} diff --git a/src/detection/cpuusage/cpuusage_bsd.c b/src/detection/cpuusage/cpuusage_bsd.c index af513878ff..a04c05b75d 100644 --- a/src/detection/cpuusage/cpuusage_bsd.c +++ b/src/detection/cpuusage/cpuusage_bsd.c @@ -6,18 +6,34 @@ #include #include +#ifdef __OpenBSD__ + #include +#endif + const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { size_t neededLength = 0; +#ifdef __OpenBSD__ + int ctls[] = {CTL_KERN, KERN_CPTIME}; + if (sysctl(ctls, 2, NULL, &neededLength, NULL, 0) != 0) + return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed"; +#else if(sysctlbyname("kern.cp_times", NULL, &neededLength, NULL, 0) != 0) return "sysctlbyname(kern.cp_times, NULL) failed"; +#endif uint32_t coreCount = (uint32_t) (neededLength / (CPUSTATES * sizeof(uint64_t))); assert(coreCount > 0); FF_AUTO_FREE uint64_t (*cpTimes)[CPUSTATES] = malloc(neededLength); + +#ifdef __OpenBSD__ + if (sysctl(ctls, 2, cpTimes, &neededLength, NULL, 0) != 0) + return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed"; +#else if(sysctlbyname("kern.cp_times", cpTimes, &neededLength, NULL, 0) != 0) return "sysctlbyname(kern.cp_times, cpTime) failed"; +#endif for (uint32_t i = 0; i < coreCount; ++i) { diff --git a/src/detection/cpuusage/cpuusage_nosupport.c b/src/detection/cpuusage/cpuusage_nosupport.c index 72770e3bec..da8bbddddf 100644 --- a/src/detection/cpuusage/cpuusage_nosupport.c +++ b/src/detection/cpuusage/cpuusage_nosupport.c @@ -1,7 +1,7 @@ #include "fastfetch.h" #include "detection/cpuusage/cpuusage.h" -const char* ffGetCpuUsageInfo(FFlist* cpuTimes) +const char* ffGetCpuUsageInfo(FF_MAYBE_UNUSED FFlist* cpuTimes) { return "Not support on this platform"; } diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 81be9c83fc..4060669c33 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -92,6 +92,11 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) }, &attrBuf, sizeof(attrBuf), 0) == 0) ffStrbufInitNS(&disk->name, attrBuf.nameRef.attr_length - 1 /* excluding '\0' */, attrBuf.nameSpace); } +#else +static void detectFsInfo(struct statfs* fs, FFDisk* disk) +{ + FF_UNUSED(fs, disk); +} #endif const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) @@ -143,6 +148,10 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) if(fs->f_flags & MNT_RDONLY) disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; + #ifdef __OpenBSD__ + #define st_birthtimespec __st_birthtim + #endif + struct stat st; if(stat(fs->f_mntonname, &st) == 0 && st.st_birthtimespec.tv_sec > 0) disk->createTime = (uint64_t)((st.st_birthtimespec.tv_sec * 1000) + (st.st_birthtimespec.tv_nsec / 1000000)); diff --git a/src/detection/disk/disk_nosupport.c b/src/detection/disk/disk_nosupport.c index cd224572ad..c680c549e6 100644 --- a/src/detection/disk/disk_nosupport.c +++ b/src/detection/disk/disk_nosupport.c @@ -1,6 +1,6 @@ #include "disk.h" -const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) +const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_UNUSED FFlist* disks) { return "Not supported on this platform"; } diff --git a/src/detection/diskio/diskio_nosupport.c b/src/detection/diskio/diskio_nosupport.c index 2e165c0c50..338c6e361a 100644 --- a/src/detection/diskio/diskio_nosupport.c +++ b/src/detection/diskio/diskio_nosupport.c @@ -1,6 +1,6 @@ #include "diskio.h" -const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) +const char* ffDiskIOGetIoCounters(FF_MAYBE_UNUSED FFlist* result, FF_MAYBE_UNUSED FFDiskIOOptions* options) { return "Not supported on this platform"; } diff --git a/src/detection/displayserver/displayserver.c b/src/detection/displayserver/displayserver.c index 74898721bc..235c00dc2c 100644 --- a/src/detection/displayserver/displayserver.c +++ b/src/detection/displayserver/displayserver.c @@ -13,7 +13,8 @@ FFDisplayResult* ffdsAppendDisplay( bool primary, uint64_t id, uint32_t physicalWidth, - uint32_t physicalHeight) + uint32_t physicalHeight, + const char* platformApi) { if(width == 0 || height == 0) return NULL; @@ -31,6 +32,7 @@ FFDisplayResult* ffdsAppendDisplay( display->physicalWidth = physicalWidth; display->physicalHeight = physicalHeight; display->primary = primary; + display->platformApi = platformApi; display->bitDepth = 0; display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNKNOWN; diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h index 5a030b12ab..d1d21839ed 100644 --- a/src/detection/displayserver/displayserver.h +++ b/src/detection/displayserver/displayserver.h @@ -70,6 +70,7 @@ typedef struct FFDisplayResult uint32_t physicalWidth; uint32_t physicalHeight; bool primary; + const char* platformApi; uint8_t bitDepth; FFDisplayHdrStatus hdrStatus; uint16_t manufactureYear; @@ -102,4 +103,5 @@ FFDisplayResult* ffdsAppendDisplay( bool primary, uint64_t id, uint32_t physicalWidth, - uint32_t physicalHeight); + uint32_t physicalHeight, + const char* platformApi); diff --git a/src/detection/displayserver/displayserver_android.c b/src/detection/displayserver/displayserver_android.c index a51d850f42..88e5b23d33 100644 --- a/src/detection/displayserver/displayserver_android.c +++ b/src/detection/displayserver/displayserver_android.c @@ -66,7 +66,8 @@ static void detectWithDumpsys(FFDisplayServerResult* ds) false, 0, 0, - 0 + 0, + "dumpsys" ); } @@ -100,7 +101,8 @@ static bool detectWithGetprop(FFDisplayServerResult* ds) false, 0, 0, - 0 + 0, + "getprop" ); } diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index b419d52c7b..006757d087 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -1,6 +1,7 @@ #include "displayserver.h" #include "util/apple/cf_helpers.h" #include "util/stringUtils.h" +#include "util/edidHelper.h" #include #include @@ -8,9 +9,9 @@ #include #include +#ifdef MAC_OS_X_VERSION_10_15 extern Boolean CoreDisplay_Display_SupportsHDRMode(CGDirectDisplayID display) __attribute__((weak_import)); extern Boolean CoreDisplay_Display_IsHDRModeEnabled(CGDirectDisplayID display) __attribute__((weak_import)); -#ifdef MAC_OS_X_VERSION_10_15 extern CFDictionaryRef CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display) __attribute__((weak_import)); #else #include @@ -23,6 +24,7 @@ static void detectDisplays(FFDisplayServerResult* ds) if(CGGetOnlineDisplayList(sizeof(screens) / sizeof(screens[0]), screens, &screenCount) != kCGErrorSuccess) return; + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); for(uint32_t i = 0; i < screenCount; i++) { CGDirectDisplayID screen = screens[i]; @@ -44,7 +46,7 @@ static void detectDisplays(FFDisplayServerResult* ds) } } - FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate(); + ffStrbufClear(&buffer); CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = NULL; #ifdef MAC_OS_X_VERSION_10_15 if(CoreDisplay_DisplayCreateInfoDictionary) @@ -55,14 +57,30 @@ static void detectDisplays(FFDisplayServerResult* ds) displayInfo = IODisplayCreateInfoDictionary(servicePort, kIODisplayOnlyPreferredName); } #endif + uint32_t physicalWidth = 0, physicalHeight = 0; if(displayInfo) { CFDictionaryRef productNames; if(!ffCfDictGetDict(displayInfo, CFSTR(kDisplayProductName), &productNames)) - ffCfDictGetString(productNames, CFSTR("en_US"), &name); + ffCfDictGetString(productNames, CFSTR("en_US"), &buffer); + + // CGDisplayScreenSize reports invalid result for external displays on old Intel MacBook Pro + CFDataRef edidRef = (CFDataRef) CFDictionaryGetValue(displayInfo, CFSTR(kIODisplayEDIDKey)); + if (edidRef && CFGetTypeID(edidRef) == CFDataGetTypeID()) + { + const uint8_t* edidData = CFDataGetBytePtr(edidRef); + uint32_t edidLength = (uint32_t) CFDataGetLength(edidRef); + if (edidLength >= 128) + ffEdidGetPhysicalSize(edidData, &physicalWidth, &physicalHeight); + } } - CGSize size = CGDisplayScreenSize(screen); + if (!physicalWidth || !physicalHeight) + { + CGSize size = CGDisplayScreenSize(screen); + physicalWidth = (uint32_t) (size.width + 0.5); + physicalHeight = (uint32_t) (size.height + 0.5); + } FFDisplayResult* display = ffdsAppendDisplay(ds, (uint32_t)CGDisplayModeGetPixelWidth(mode), @@ -71,12 +89,13 @@ static void detectDisplays(FFDisplayServerResult* ds) (uint32_t)CGDisplayModeGetWidth(mode), (uint32_t)CGDisplayModeGetHeight(mode), (uint32_t)CGDisplayRotation(screen), - &name, + &buffer, CGDisplayIsBuiltin(screen) ? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL, CGDisplayIsMain(screen), (uint64_t)screen, - (uint32_t) (size.width + 0.5), - (uint32_t) (size.height + 0.5) + physicalWidth, + physicalHeight, + "CoreGraphics" ); if (display) { @@ -93,20 +112,26 @@ static void detectDisplays(FFDisplayServerResult* ds) if (display->type == FF_DISPLAY_TYPE_BUILTIN) display->hdrStatus = CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance")) ? FF_DISPLAY_HDR_STATUS_SUPPORTED : FF_DISPLAY_HDR_STATUS_UNSUPPORTED; + #ifdef MAC_OS_X_VERSION_10_15 else if (CoreDisplay_Display_SupportsHDRMode) { if (CoreDisplay_Display_SupportsHDRMode(screen)) { - if (CoreDisplay_Display_IsHDRModeEnabled) - { - display->hdrStatus = CoreDisplay_Display_IsHDRModeEnabled(screen) - ? FF_DISPLAY_HDR_STATUS_ENABLED - : FF_DISPLAY_HDR_STATUS_SUPPORTED; - } - else - display->hdrStatus = FF_DISPLAY_HDR_STATUS_SUPPORTED; + display->hdrStatus = FF_DISPLAY_HDR_STATUS_SUPPORTED; + if (CoreDisplay_Display_IsHDRModeEnabled && CoreDisplay_Display_IsHDRModeEnabled(screen)) + display->hdrStatus = FF_DISPLAY_HDR_STATUS_ENABLED; } + else + display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNSUPPORTED; } + #endif + + display->serial = CGDisplaySerialNumber(screen); + int value; + if (ffCfDictGetInt(displayInfo, CFSTR(kDisplayYearOfManufacture), &value) == NULL) + display->manufactureYear = (uint16_t) value; + if (ffCfDictGetInt(displayInfo, CFSTR(kDisplayWeekOfManufacture), &value) == NULL) + display->manufactureWeek = (uint16_t) value; } CGDisplayModeRelease(mode); } diff --git a/src/detection/displayserver/displayserver_windows.c b/src/detection/displayserver/displayserver_windows.c index 11d9a5de76..1b13b11a6c 100644 --- a/src/detection/displayserver/displayserver_windows.c +++ b/src/detection/displayserver/displayserver_windows.c @@ -165,7 +165,8 @@ static void detectDisplays(FFDisplayServerResult* ds) !!(monitorInfo->info.dwFlags & MONITORINFOF_PRIMARY), (uint64_t)(uintptr_t) monitorInfo->handle, physicalWidth, - physicalHeight + physicalHeight, + "GDI" ); if (display) diff --git a/src/detection/displayserver/linux/displayserver_linux.c b/src/detection/displayserver/linux/displayserver_linux.c index a841776503..cc4e07b21b 100644 --- a/src/detection/displayserver/linux/displayserver_linux.c +++ b/src/detection/displayserver/linux/displayserver_linux.c @@ -86,7 +86,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) if (ffSettingsGetFreeBSDKenv("screen.height", &buf)) { uint32_t height = (uint32_t) ffStrbufToUInt(&buf, 0); - ffdsAppendDisplay(ds, width, height, 0, 0, 0, 0, NULL, FF_DISPLAY_TYPE_UNKNOWN, false, 0, 0, 0); + ffdsAppendDisplay(ds, width, height, 0, 0, 0, 0, NULL, FF_DISPLAY_TYPE_UNKNOWN, false, 0, 0, 0, "kenv"); } } } diff --git a/src/detection/displayserver/linux/drm.c b/src/detection/displayserver/linux/drm.c index 56a16d3f75..2598d80ff7 100644 --- a/src/detection/displayserver/linux/drm.c +++ b/src/detection/displayserver/linux/drm.c @@ -90,7 +90,8 @@ static const char* drmParseSysfs(FFDisplayServerResult* result) false, 0, physicalWidth, - physicalHeight + physicalHeight, + "sysfs-drm" ); if (item && edidLength) { @@ -390,7 +391,8 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result) false, conn->connector_id, conn->mmWidth, - conn->mmHeight + conn->mmHeight, + "libdrm" ); if (item) diff --git a/src/detection/displayserver/linux/wayland/global-output.c b/src/detection/displayserver/linux/wayland/global-output.c index 20227be364..ab9fc5c2fd 100644 --- a/src/detection/displayserver/linux/wayland/global-output.c +++ b/src/detection/displayserver/linux/wayland/global-output.c @@ -129,7 +129,8 @@ void ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry* regist false, display.id, (uint32_t) display.physicalWidth, - (uint32_t) display.physicalHeight + (uint32_t) display.physicalHeight, + "wayland-global" ); if (item) { diff --git a/src/detection/displayserver/linux/wayland/kde-output.c b/src/detection/displayserver/linux/wayland/kde-output.c index 0993f72a5f..ab8a9eb93a 100644 --- a/src/detection/displayserver/linux/wayland/kde-output.c +++ b/src/detection/displayserver/linux/wayland/kde-output.c @@ -194,7 +194,8 @@ void ffWaylandHandleKdeOutput(WaylandData* wldata, struct wl_registry* registry, false, display.id, (uint32_t) display.physicalWidth, - (uint32_t) display.physicalHeight + (uint32_t) display.physicalHeight, + "wayland-kde" ); if (item) { diff --git a/src/detection/displayserver/linux/wayland/wayland.c b/src/detection/displayserver/linux/wayland/wayland.c index 5a67f7887f..457b334ee6 100644 --- a/src/detection/displayserver/linux/wayland/wayland.c +++ b/src/detection/displayserver/linux/wayland/wayland.c @@ -109,7 +109,7 @@ static bool matchDrmConnector(const char* connName, WaylandDisplay* wldata) uint8_t edidData[512]; ssize_t edidLength = ffReadFileData(path.chars, sizeof(edidData), edidData); - if (edidLength <= 0 || edidLength % 128 != 0) + if (edidLength > 0 && edidLength % 128 == 0) { ffEdidGetName(edidData, &wldata->edidName); ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength); diff --git a/src/detection/displayserver/linux/wayland/zwlr-output.c b/src/detection/displayserver/linux/wayland/zwlr-output.c index 7e23d593e8..c54818a64a 100644 --- a/src/detection/displayserver/linux/wayland/zwlr-output.c +++ b/src/detection/displayserver/linux/wayland/zwlr-output.c @@ -138,7 +138,8 @@ static void waylandHandleZwlrHead(void *data, FF_MAYBE_UNUSED struct zwlr_output false, display.id, (uint32_t) display.physicalWidth, - (uint32_t) display.physicalHeight + (uint32_t) display.physicalHeight, + "wayland-zwlr" ); if (item) { diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index 9d174b5ea7..b9d6c32485 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -12,6 +12,10 @@ #include #include #include +#elif defined(__OpenBSD__) + #include + #include + #include #elif defined(__sun) #include #endif @@ -252,7 +256,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result) { uint32_t userId = getuid(); -#ifdef __FreeBSD__ +#if __FreeBSD__ int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) userId}; size_t length = 0; @@ -276,7 +280,26 @@ static const char* getFromProcesses(FFDisplayServerResult* result) if(result->dePrettyName.length > 0 && result->wmPrettyName.length > 0) break; } -#elif defined(__sun) +#elif __OpenBSD__ + kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL); + int count = 0; + const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, userId, sizeof(struct kinfo_proc), &count); + if (proc) + { + for (int i = 0; i < count; ++i) + { + if(result->dePrettyName.length == 0) + applyPrettyNameIfDE(result, proc->p_comm); + + if(result->wmPrettyName.length == 0) + applyNameIfWM(result, proc->p_comm); + + if(result->dePrettyName.length > 0 && result->wmPrettyName.length > 0) + break; + } + } + kvm_close(kd); +#elif __sun FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc"); if(procdir == NULL) return "opendir(\"/proc\") failed"; @@ -312,7 +335,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result) break; } } -#else +#elif __linux__ FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc"); if(procdir == NULL) return "opendir(\"/proc\") failed"; diff --git a/src/detection/displayserver/linux/xcb.c b/src/detection/displayserver/linux/xcb.c index d40386eb0b..a9e4b8d795 100644 --- a/src/detection/displayserver/linux/xcb.c +++ b/src/detection/displayserver/linux/xcb.c @@ -118,7 +118,8 @@ const char* ffdsConnectXcb(FFDisplayServerResult* result) false, 0, (uint32_t) screen->width_in_millimeters, - (uint32_t) screen->height_in_millimeters + (uint32_t) screen->height_in_millimeters, + "xcb" ); ffxcb_screen_next(&iterator); } @@ -239,12 +240,14 @@ static bool xcbRandrHandleCrtc(XcbRandrData* data, xcb_randr_crtc_t crtc, FFstrb primary, 0, (uint32_t) output->mm_width, - (uint32_t) output->mm_height + (uint32_t) output->mm_height, + "xcb-randr-crtc" ); if (item && edidLength) { item->hdrStatus = ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength) ? FF_DISPLAY_HDR_STATUS_SUPPORTED : FF_DISPLAY_HDR_STATUS_UNSUPPORTED; ffEdidGetSerialAndManufactureDate(edidData, &item->serial, &item->manufactureYear, &item->manufactureWeek); + ffEdidGetPhysicalSize(edidData, &item->physicalWidth, &item->physicalHeight); } return !!item; @@ -326,7 +329,8 @@ static bool xcbRandrHandleMonitor(XcbRandrData* data, xcb_randr_monitor_info_t* !!monitor->primary, 0, (uint32_t) monitor->width_in_millimeters, - (uint32_t) monitor->height_in_millimeters + (uint32_t) monitor->height_in_millimeters, + "xcb-randr-monitor" ); } @@ -380,7 +384,8 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen) false, 0, (uint32_t) screen->width_in_millimeters, - (uint32_t) screen->height_in_millimeters + (uint32_t) screen->height_in_millimeters, + "xcb-randr-screen" ); } diff --git a/src/detection/displayserver/linux/xlib.c b/src/detection/displayserver/linux/xlib.c index e83b0e1ede..00ef3ce7ce 100644 --- a/src/detection/displayserver/linux/xlib.c +++ b/src/detection/displayserver/linux/xlib.c @@ -89,7 +89,8 @@ const char* ffdsConnectXlib(FFDisplayServerResult* result) false, 0, (uint32_t) WidthMMOfScreen(screen), - (uint32_t) HeightMMOfScreen(screen) + (uint32_t) HeightMMOfScreen(screen), + "xlib" ); } @@ -193,13 +194,15 @@ static bool xrandrHandleCrtc(XrandrData* data, XRROutputInfo* output, FFstrbuf* primary, 0, (uint32_t) output->mm_width, - (uint32_t) output->mm_height + (uint32_t) output->mm_height, + "xlib-randr-crtc" ); if (edidLength) { item->hdrStatus = ffEdidGetHdrCompatible(edidData, edidLength) ? FF_DISPLAY_HDR_STATUS_SUPPORTED : FF_DISPLAY_HDR_STATUS_UNSUPPORTED; ffEdidGetSerialAndManufactureDate(edidData, &item->serial, &item->manufactureYear, &item->manufactureWeek); + ffEdidGetPhysicalSize(edidData, &item->physicalWidth, &item->physicalHeight); } data->ffXRRFreeCrtcInfo(crtcInfo); @@ -267,7 +270,8 @@ static bool xrandrHandleMonitor(XrandrData* data, XRRMonitorInfo* monitorInfo) !!monitorInfo->primary, 0, (uint32_t) monitorInfo->mwidth, - (uint32_t) monitorInfo->mheight + (uint32_t) monitorInfo->mheight, + "xlib-randr-monitor" ); } @@ -317,7 +321,8 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen) false, 0, (uint32_t) WidthMMOfScreen(screen), - (uint32_t) HeightMMOfScreen(screen) + (uint32_t) HeightMMOfScreen(screen), + "xlib_randr_screen" ); } diff --git a/src/detection/dns/dns_linux.c b/src/detection/dns/dns_linux.c index 84b2f91790..1179ea4a96 100644 --- a/src/detection/dns/dns_linux.c +++ b/src/detection/dns/dns_linux.c @@ -17,11 +17,14 @@ const char* ffDetectDNS(FFDNSOptions* options, FFlist* results) { if (ffStrStartsWith(line, "nameserver")) { - const char* nameserver = line + strlen("nameserver"); + char* nameserver = line + strlen("nameserver"); while (*nameserver == ' ' || *nameserver == '\t') nameserver++; if (*nameserver == '\0') continue; + char* comment = strchr(nameserver, '#'); + if (comment) *comment = '\0'; + if ((ffStrContainsC(nameserver, ':') && !(options->showType & FF_DNS_TYPE_IPV6_BIT)) || (ffStrContainsC(nameserver, '.') && !(options->showType & FF_DNS_TYPE_IPV4_BIT))) continue; diff --git a/src/detection/gamepad/gamepad_bsd.c b/src/detection/gamepad/gamepad_bsd.c index 340ff11657..5bcc100b82 100644 --- a/src/detection/gamepad/gamepad_bsd.c +++ b/src/detection/gamepad/gamepad_bsd.c @@ -31,8 +31,9 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) if (HID_PAGE(hItem.usage) != 1) continue; switch (HID_USAGE(hItem.usage)) { - case 1: // FreeBSD returns 1 for my Pro Controller for some reason - case 5: + case 1: // Pointer. FreeBSD returns 1 for my Pro Controller for some reason + case 4: // Joystick + case 5: // Gamepad break; default: continue; diff --git a/src/detection/gamepad/gamepad_linux.c b/src/detection/gamepad/gamepad_linux.c index 50d04df5ef..8086289341 100644 --- a/src/detection/gamepad/gamepad_linux.c +++ b/src/detection/gamepad/gamepad_linux.c @@ -68,7 +68,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) { if (!ffStrStartsWith(entry->d_name, "js")) continue; - if (!ffCharIsDigit(entry->d_name[2])) + if (!ffCharIsDigit(entry->d_name[strlen("js")])) continue; ffStrbufAppendS(&path, entry->d_name); diff --git a/src/detection/gamepad/gamepad_windows.c b/src/detection/gamepad/gamepad_windows.c index ab4540af08..f9652a0e6c 100644 --- a/src/detection/gamepad/gamepad_windows.c +++ b/src/detection/gamepad/gamepad_windows.c @@ -78,7 +78,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) for (UINT i = 0; i < nDevices; ++i) { - if (pRawInputDeviceList[i].dwType != 2) continue; + if (pRawInputDeviceList[i].dwType != RIM_TYPEHID) continue; HANDLE hDevice = pRawInputDeviceList[i].hDevice; @@ -87,7 +87,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) == (UINT) -1) continue; - if (rdi.hid.usUsagePage != 1 || rdi.hid.usUsage != 5) // Gamepad + if (rdi.hid.usUsagePage != 1 || (rdi.hid.usUsage != 4/*Joystick*/ && rdi.hid.usUsage != 5/*Gamepad*/)) continue; WCHAR devName[MAX_PATH] = L""; @@ -104,7 +104,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) if (knownGamepad) ffStrbufSetS(&device->name, knownGamepad); HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - if (!hHidFile) + if (hHidFile == INVALID_HANDLE_VALUE) { if (!knownGamepad) ffStrbufSetF(&device->name, "Unknown gamepad %04X-%04X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId); @@ -131,6 +131,10 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) } } + wchar_t serialNumber[127] = L""; + if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber))) + ffStrbufSetWS(&device->serial, serialNumber); + PHIDP_PREPARSED_DATA preparsedData = NULL; if (HidD_GetPreparsedData(hHidFile, &preparsedData)) { @@ -140,10 +144,6 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) if (!NT_SUCCESS(capsResult)) continue; - wchar_t serialNumber[127] = L""; - if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber))) - ffStrbufSetWS(&device->serial, serialNumber); - if ( (rdi.hid.dwVendorId == 0x054C && ( rdi.hid.dwProductId == 0x05C4 || // PS4 Gen1 diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index c3678d6e60..6fe350d564 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -78,7 +78,7 @@ static bool pciDetectDriver(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* buffer return true; } -static const char* drmFindRenderFromCard(const char* drmCardKey, FFstrbuf* result) +FF_MAYBE_UNUSED static const char* drmFindRenderFromCard(const char* drmCardKey, FFstrbuf* result) { char path[PATH_MAX]; sprintf(path, "/sys/class/drm/%s/device/drm", drmCardKey); @@ -395,6 +395,7 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, } return NULL; #else + FF_UNUSED(gpu, drmKey, buffer); return "Fastfetch is not compiled with drm support"; #endif } diff --git a/src/detection/host/host_nosupport.c b/src/detection/host/host_nosupport.c index 6f39348236..29a54ebc98 100644 --- a/src/detection/host/host_nosupport.c +++ b/src/detection/host/host_nosupport.c @@ -1,6 +1,6 @@ #include "host.h" -const char* ffDetectHost(FFHostResult* host) +const char* ffDetectHost(FF_MAYBE_UNUSED FFHostResult* host) { return "Not supported on this platform"; } diff --git a/src/detection/host/host_obsd.c b/src/detection/host/host_obsd.c new file mode 100644 index 0000000000..960248ab3a --- /dev/null +++ b/src/detection/host/host_obsd.c @@ -0,0 +1,19 @@ +#include "host.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectHost(FFHostResult* host) +{ + const char* error = NULL; + if ((error = ffSysctlGetString(CTL_HW, HW_PRODUCT, &host->name))) + return error; + ffCleanUpSmbiosValue(&host->name); + if (ffSysctlGetString(CTL_HW, HW_VENDOR, &host->vendor) == NULL) + ffCleanUpSmbiosValue(&host->vendor); + if (ffSysctlGetString(CTL_HW, HW_VERSION, &host->version) == NULL) + ffCleanUpSmbiosValue(&host->version); + if (ffSysctlGetString(CTL_HW, HW_SERIALNO, &host->serial) == NULL) + ffCleanUpSmbiosValue(&host->serial); + + return NULL; +} diff --git a/src/detection/keyboard/keyboard.h b/src/detection/keyboard/keyboard.h new file mode 100644 index 0000000000..8f0a8a85ec --- /dev/null +++ b/src/detection/keyboard/keyboard.h @@ -0,0 +1,9 @@ +#include "fastfetch.h" + +typedef struct FFKeyboardDevice +{ + FFstrbuf serial; + FFstrbuf name; +} FFKeyboardDevice; + +const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */); diff --git a/src/detection/keyboard/keyboard_apple.c b/src/detection/keyboard/keyboard_apple.c new file mode 100644 index 0000000000..46278c5aab --- /dev/null +++ b/src/detection/keyboard/keyboard_apple.c @@ -0,0 +1,42 @@ +#include "keyboard.h" +#include "util/apple/cf_helpers.h" +#include "util/mallocHelper.h" + +#include +#include + +static void enumSet(IOHIDDeviceRef value, FFlist* results) +{ + FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(results); + ffStrbufInit(&device->serial); + ffStrbufInit(&device->name); + + CFStringRef product = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDProductKey)); + ffCfStrGetString(product, &device->name); + + CFStringRef serialNumber = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDSerialNumberKey)); + ffCfStrGetString(serialNumber, &device->serial); +} + +const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) +{ + IOHIDManagerRef FF_CFTYPE_AUTO_RELEASE manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); + if (IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) + return "IOHIDManagerOpen() failed"; + + CFDictionaryRef FF_CFTYPE_AUTO_RELEASE matching1 = CFDictionaryCreate(kCFAllocatorDefault, (const void **)(CFStringRef[]){ + CFSTR(kIOHIDDeviceUsagePageKey), + CFSTR(kIOHIDDeviceUsageKey) + }, (const void **)(CFNumberRef[]){ + ffCfCreateInt(kHIDPage_GenericDesktop), + ffCfCreateInt(kHIDUsage_GD_Keyboard) + }, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + IOHIDManagerSetDeviceMatching(manager, matching1); + + CFSetRef FF_CFTYPE_AUTO_RELEASE set = IOHIDManagerCopyDevices(manager); + if (set) + CFSetApplyFunction(set, (CFSetApplierFunction) &enumSet, devices); + IOHIDManagerClose(manager, kIOHIDOptionsTypeNone); + + return NULL; +} diff --git a/src/detection/keyboard/keyboard_bsd.c b/src/detection/keyboard/keyboard_bsd.c new file mode 100644 index 0000000000..c1be06aa4a --- /dev/null +++ b/src/detection/keyboard/keyboard_bsd.c @@ -0,0 +1,47 @@ +#include "keyboard.h" +#include "common/io/io.h" + +#include +#include +#include +#include + +#define MAX_UHID_JOYS 64 + +const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) +{ + char path[16]; + for (int i = 0; i < MAX_UHID_JOYS; i++) + { + snprintf(path, sizeof(path), "/dev/uhid%d", i); + FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); + if (fd < 0) continue; + + report_desc_t repDesc = hid_get_report_desc(fd); + if (!repDesc) continue; + + int reportId = hid_get_report_id(fd); + + struct hid_data* hData = hid_start_parse(repDesc, 0, reportId); + if (hData) + { + struct hid_item hItem; + while (hid_get_item(hData, &hItem) > 0) + { + if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 6) continue; + + struct usb_device_info di; + if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1) + { + FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices); + ffStrbufInitS(&device->serial, di.udi_serial); + ffStrbufInitS(&device->name, di.udi_product); + } + } + } + + hid_dispose_report_desc(repDesc); + } + + return NULL; +} diff --git a/src/detection/keyboard/keyboard_linux.c b/src/detection/keyboard/keyboard_linux.c new file mode 100644 index 0000000000..42618272fb --- /dev/null +++ b/src/detection/keyboard/keyboard_linux.c @@ -0,0 +1,57 @@ +#include "keyboard.h" +#include "common/io/io.h" +#include "util/stringUtils.h" + +const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) +{ + // There is no /sys/class/input/kbd* on Linux + FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/dev/input/by-path/"); + if (dirp == NULL) + return "opendir(\"/dev/input/by-path/\") == NULL"; + + uint64_t flags = 0; + + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); + + struct dirent* entry; + while ((entry = readdir(dirp)) != NULL) + { + if (!ffStrEndsWith(entry->d_name, "-event-kbd")) + continue; + + char buffer[32]; // `../eventX` + ssize_t len = readlinkat(dirfd(dirp), entry->d_name, buffer, sizeof(buffer) - 1); + if (len != strlen("../eventX") || !ffStrStartsWith(buffer, "../event")) continue; + buffer[len] = 0; + + const char* eventid = buffer + strlen("../event"); + + char* pend = NULL; + uint32_t index = (uint32_t) strtoul(eventid, &pend, 10); + if (pend == eventid) continue; + + // Ignore duplicate entries + if (flags & (1 << index)) + continue; + flags |= (1 << index); + + ffStrbufSetF(&path, "/sys/class/input/event%s/device/name", eventid); + + FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate(); + if (ffAppendFileBuffer(path.chars, &name)) + { + ffStrbufTrimRightSpace(&name); + ffStrbufSubstrBefore(&path, path.length - 4); + + FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices); + ffStrbufInitMove(&device->name, &name); + ffStrbufInit(&device->serial); + + ffStrbufAppendS(&path, "uniq"); + if (ffAppendFileBuffer(path.chars, &device->serial)) + ffStrbufTrimRightSpace(&device->serial); + } + } + + return NULL; +} diff --git a/src/detection/keyboard/keyboard_nosupport.c b/src/detection/keyboard/keyboard_nosupport.c new file mode 100644 index 0000000000..c6431c8fbe --- /dev/null +++ b/src/detection/keyboard/keyboard_nosupport.c @@ -0,0 +1,6 @@ +#include "keyboard.h" + +const char* ffDetectKeyboard(FF_MAYBE_UNUSED FFlist* devices /* List of FFKeyboardDevice */) +{ + return "No mouse support on this platform"; +} diff --git a/src/detection/keyboard/keyboard_windows.c b/src/detection/keyboard/keyboard_windows.c new file mode 100644 index 0000000000..cf8acabb3f --- /dev/null +++ b/src/detection/keyboard/keyboard_windows.c @@ -0,0 +1,91 @@ +#define INITGUID + +#include "keyboard.h" +#include "common/io/io.h" +#include "util/mallocHelper.h" +#include "util/windows/unicode.h" + +#include +#include +#include +#include +#include + +WINAPI CMAPI CONFIGRET CM_Get_Device_Interface_PropertyW( + _In_ LPCWSTR pszDeviceInterface, + _In_ const DEVPROPKEY *PropertyKey, + _Out_ DEVPROPTYPE *PropertyType, + _Out_ PBYTE PropertyBuffer, + _Inout_ PULONG PropertyBufferSize, + _In_ ULONG ulFlags +); + +const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) +{ + UINT nDevices = 0; + if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST))) + return "GetRawInputDeviceList(NULL) failed"; + if (nDevices == 0) + return "No HID devices found"; + + RAWINPUTDEVICELIST* FF_AUTO_FREE pRawInputDeviceList = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); + if ((nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == (UINT) -1) + return "GetRawInputDeviceList(pRawInputDeviceList) failed"; + + + for (UINT i = 0; i < nDevices; ++i) + { + if (pRawInputDeviceList[i].dwType != RIM_TYPEKEYBOARD) continue; + + HANDLE hDevice = pRawInputDeviceList[i].hDevice; + + RID_DEVICE_INFO rdi; + UINT rdiSize = sizeof(rdi); + if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) == (UINT) -1) + continue; + + WCHAR devName[MAX_PATH]; + UINT nameSize = MAX_PATH; + if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICENAME, devName, &nameSize) == (UINT) -1) + continue; + + FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices); + ffStrbufInit(&device->serial); + ffStrbufInit(&device->name); + + wchar_t buffer[MAX_PATH]; + + HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, 0 /* must be 0 instead of GENERIC_READ */, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (hHidFile != INVALID_HANDLE_VALUE) + { + if (HidD_GetProductString(hHidFile, buffer, (ULONG) sizeof(buffer))) + ffStrbufSetWS(&device->name, buffer); + + if (HidD_GetSerialNumberString(hHidFile, buffer, sizeof(buffer))) + ffStrbufSetWS(&device->serial, buffer); + } + + if (!device->name.length) + { + // https://stackoverflow.com/a/64321096/9976392 + DEVPROPTYPE propertyType; + ULONG propertySize = sizeof(buffer); + + if (CM_Get_Device_Interface_PropertyW(devName, &DEVPKEY_Device_InstanceId, &propertyType, (PBYTE) buffer, &propertySize, 0) == CR_SUCCESS) + { + DEVINST devInst; + if (CM_Locate_DevNodeW(&devInst, buffer, CM_LOCATE_DEVNODE_NORMAL) == CR_SUCCESS) + { + propertySize = sizeof(buffer); + if (CM_Get_DevNode_PropertyW(devInst, &DEVPKEY_NAME, &propertyType, (PBYTE) buffer, &propertySize, 0) == CR_SUCCESS) + ffStrbufSetWS(&device->name, buffer); + } + } + } + + if (!device->name.length) + ffStrbufSetF(&device->name, "Unknown device %04X-%04X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId); + } + + return NULL; +} diff --git a/src/detection/loadavg/loadavg_bsd.c b/src/detection/loadavg/loadavg_bsd.c index 71c4304c13..3a0b6bca57 100644 --- a/src/detection/loadavg/loadavg_bsd.c +++ b/src/detection/loadavg/loadavg_bsd.c @@ -2,10 +2,12 @@ #include -#ifdef __FreeBSD__ +#if __FreeBSD__ || __OpenBSD__ #include #include - #include + #if __FreeBSD__ + #include + #endif #endif const char* ffDetectLoadavg(double result[3]) diff --git a/src/detection/localip/localip.h b/src/detection/localip/localip.h index 859d5340fa..11ac50e558 100644 --- a/src/detection/localip/localip.h +++ b/src/detection/localip/localip.h @@ -8,9 +8,30 @@ typedef struct FFLocalIpResult FFstrbuf ipv4; FFstrbuf ipv6; FFstrbuf mac; + FFstrbuf flags; int32_t mtu; int32_t speed; bool defaultRoute; } FFLocalIpResult; +typedef struct FFLocalIpNIFlag +{ + uint32_t flag; + const char *name; +} FFLocalIpNIFlag; + +static inline void ffLocalIpFillNIFlags(FFstrbuf *buf, uint32_t flag, const FFLocalIpNIFlag names[]) +{ + for (const FFLocalIpNIFlag *nf = names; flag && nf->name; ++nf) + { + if (flag & nf->flag) + { + if (buf->length > 0) + ffStrbufAppendC(buf, ','); + ffStrbufAppendS(buf, nf->name); + flag &= ~nf->flag; + } + } +} + const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results); diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index 9dd8aaeacd..243091ddfb 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -15,9 +15,10 @@ #ifdef __linux__ #include #include +#include #endif -#if defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) #include #include #else @@ -27,7 +28,48 @@ #include #endif -static void addNewIp(FFlist* list, const char* name, const char* addr, int type, bool defaultRoute, bool firstOnly) +static const FFLocalIpNIFlag niFlagOptions[] = { + { IFF_UP, "UP" }, + { IFF_BROADCAST, "BROADCAST" }, + { IFF_DEBUG, "DEBUG" }, + { IFF_LOOPBACK, "LOOPBACK" }, + { IFF_POINTOPOINT, "POINTOPOINT" }, + { IFF_RUNNING, "RUNNING" }, + { IFF_NOARP, "NOARP" }, + { IFF_PROMISC, "PROMISC" }, + { IFF_ALLMULTI, "ALLMULTI" }, + { IFF_MULTICAST, "MULTICAST" }, +#if defined(__linux__) || defined(__APPLE__) || defined(__sun) + { IFF_NOTRAILERS, "NOTRAILERS" }, +#endif +#ifdef __linux__ + { IFF_MASTER, "MASTER" }, + { IFF_SLAVE, "SLAVE" }, + { IFF_PORTSEL, "PORTSEL" }, + { IFF_AUTOMEDIA, "AUTOMEDIA" }, + { IFF_DYNAMIC, "DYNAMIC" }, + { IFF_LOWER_UP, "LOWER_UP" }, + { IFF_DORMANT, "DORMANT" }, + { IFF_ECHO, "ECHO" }, +#endif +#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) + { IFF_OACTIVE, "OACTIVE" }, + { IFF_SIMPLEX, "SIMPLEX" }, + { IFF_LINK0, "LINK0" }, + { IFF_LINK1, "LINK1" }, + { IFF_LINK2, "LINK2" }, +#endif +#if defined(__FreeBSD__) || defined(__APPLE__) + { IFF_ALTPHYS, "ALTPHYS" }, +#endif +#ifdef __FreeBSD__ + { IFF_CANTCONFIG, "CANTCONFIG" }, +#endif + // sentinel + {}, +}; + +static void addNewIp(FFlist* list, const char* name, const char* addr, int type, bool defaultRoute, uint32_t flags, bool firstOnly) { FFLocalIpResult* ip = NULL; @@ -44,9 +86,12 @@ static void addNewIp(FFlist* list, const char* name, const char* addr, int type, ffStrbufInit(&ip->ipv4); ffStrbufInit(&ip->ipv6); ffStrbufInit(&ip->mac); + ffStrbufInit(&ip->flags); ip->defaultRoute = defaultRoute; ip->mtu = -1; ip->speed = -1; + + ffLocalIpFillNIFlags(&ip->flags, flags, niFlagOptions); } switch (type) @@ -96,6 +141,8 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) if (options->namePrefix.length && strncmp(ifa->ifa_name, options->namePrefix.chars, options->namePrefix.length) != 0) continue; + uint32_t flags = options->showType & FF_LOCALIP_TYPE_FLAGS_BIT ? ifa->ifa_flags : 0; + if (ifa->ifa_addr->sa_family == AF_INET) { if (!(options->showType & FF_LOCALIP_TYPE_IPV4_BIT)) @@ -116,7 +163,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) } } - addNewIp(results, ifa->ifa_name, addressBuffer, AF_INET, isDefaultRoute, !(options->showType & FF_LOCALIP_TYPE_ALL_IPS_BIT)); + addNewIp(results, ifa->ifa_name, addressBuffer, AF_INET, isDefaultRoute, flags, !(options->showType & FF_LOCALIP_TYPE_ALL_IPS_BIT)); } else if (ifa->ifa_addr->sa_family == AF_INET6) { @@ -141,9 +188,9 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) } } - addNewIp(results, ifa->ifa_name, addressBuffer, AF_INET6, isDefaultRoute, !(options->showType & FF_LOCALIP_TYPE_ALL_IPS_BIT)); + addNewIp(results, ifa->ifa_name, addressBuffer, AF_INET6, isDefaultRoute, flags, !(options->showType & FF_LOCALIP_TYPE_ALL_IPS_BIT)); } - #if defined(__FreeBSD__) || defined(__APPLE__) + #if __FreeBSD__ || __OpenBSD__ || __APPLE__ else if (ifa->ifa_addr->sa_family == AF_LINK) { if (!(options->showType & FF_LOCALIP_TYPE_MAC_BIT)) @@ -153,7 +200,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) uint8_t* ptr = (uint8_t*) LLADDR((struct sockaddr_dl *)ifa->ifa_addr); snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); - addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, false); + addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, flags, false); } #else else if (ifa->ifa_addr->sa_family == AF_PACKET) @@ -165,7 +212,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) uint8_t* ptr = ((struct sockaddr_ll *)ifa->ifa_addr)->sll_addr; snprintf(addressBuffer, sizeof(addressBuffer), "%02x:%02x:%02x:%02x:%02x:%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); - addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, false); + addNewIp(results, ifa->ifa_name, addressBuffer, -1, isDefaultRoute, flags, false); } #endif } @@ -199,7 +246,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) ifr.ifr_data = (void*) &edata; if (ioctl(sockfd, SIOCETHTOOL, &ifr) == 0) iface->speed = (edata.speed_hi << 16) | edata.speed; // ethtool_cmd_speed is not available on Android - #elif __FreeBSD__ || __APPLE__ + #elif __FreeBSD__ || __APPLE__ || __OpenBSD__ struct ifmediareq ifmr = {}; strncpy(ifmr.ifm_name, iface->name.chars, IFNAMSIZ - 1); if (ioctl(sockfd, SIOCGIFMEDIA, &ifmr) == 0 && (IFM_TYPE(ifmr.ifm_active) & IFM_ETHER)) diff --git a/src/detection/localip/localip_windows.c b/src/detection/localip/localip_windows.c index a24d38591b..00fee43ed0 100644 --- a/src/detection/localip/localip_windows.c +++ b/src/detection/localip/localip_windows.c @@ -6,6 +6,21 @@ #include "util/windows/unicode.h" #include "localip.h" +static const FFLocalIpNIFlag niFlagOptions[] = { + { IP_ADAPTER_DDNS_ENABLED, "DDNS_ENABLED" }, + { IP_ADAPTER_REGISTER_ADAPTER_SUFFIX, "REGISTER_ADAPTER_SUFFIX" }, + { IP_ADAPTER_DHCP_ENABLED, "DHCP_ENABLED" }, + { IP_ADAPTER_RECEIVE_ONLY, "RECEIVE_ONLY" }, + { IP_ADAPTER_NO_MULTICAST, "NO_MULTICAST" }, + { IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG, "IPV6_OTHER_STATEFUL_CONFIG" }, + { IP_ADAPTER_NETBIOS_OVER_TCPIP_ENABLED, "NETBIOS_OVER_TCPIP_ENABLED" }, + { IP_ADAPTER_IPV4_ENABLED, "IPV4_ENABLED" }, + { IP_ADAPTER_IPV6_ENABLED, "IPV6_ENABLED" }, + { IP_ADAPTER_IPV6_MANAGE_ADDRESS_CONFIG, "IPV6_MANAGE_ADDRESS_CONFIG" }, + // sentinel + {}, +}; + static void addNewIp(FFlist* list, const char* name, const char* addr, int type, bool newIp, bool defaultRoute) { FFLocalIpResult* ip = NULL; @@ -17,6 +32,7 @@ static void addNewIp(FFlist* list, const char* name, const char* addr, int type, ffStrbufInit(&ip->ipv4); ffStrbufInit(&ip->ipv6); ffStrbufInit(&ip->mac); + ffStrbufInit(&ip->flags); ip->defaultRoute = defaultRoute; ip->speed = -1; ip->mtu = -1; @@ -113,13 +129,13 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) if (!(typesToAdd & (FF_LOCALIP_TYPE_IPV4_BIT | FF_LOCALIP_TYPE_ALL_IPS_BIT))) continue; SOCKADDR_IN* ipv4 = (SOCKADDR_IN*) ifa->Address.lpSockaddr; - char addressBuffer[INET_ADDRSTRLEN + 4]; + char addressBuffer[INET_ADDRSTRLEN + 6]; inet_ntop(AF_INET, &ipv4->sin_addr, addressBuffer, INET_ADDRSTRLEN); if ((options->showType & FF_LOCALIP_TYPE_PREFIX_LEN_BIT) && ifa->OnLinkPrefixLength) { size_t len = strlen(addressBuffer); - snprintf(addressBuffer + len, 4, "/%u", (unsigned) ifa->OnLinkPrefixLength); + snprintf(addressBuffer + len, 6, "/%u", (unsigned) ifa->OnLinkPrefixLength); } addNewIp(results, name, addressBuffer, AF_INET, newIp, isDefaultRoute); @@ -133,13 +149,13 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) if (!(typesToAdd & (FF_LOCALIP_TYPE_IPV6_BIT | FF_LOCALIP_TYPE_ALL_IPS_BIT))) continue; SOCKADDR_IN6* ipv6 = (SOCKADDR_IN6*) ifa->Address.lpSockaddr; - char addressBuffer[INET6_ADDRSTRLEN + 4]; + char addressBuffer[INET6_ADDRSTRLEN + 6]; inet_ntop(AF_INET6, &ipv6->sin6_addr, addressBuffer, INET6_ADDRSTRLEN); if ((options->showType & FF_LOCALIP_TYPE_PREFIX_LEN_BIT) && ifa->OnLinkPrefixLength) { size_t len = strlen(addressBuffer); - snprintf(addressBuffer + len, 4, "/%u", (unsigned) ifa->OnLinkPrefixLength); + snprintf(addressBuffer + len, 6, "/%u", (unsigned) ifa->OnLinkPrefixLength); } addNewIp(results, name, addressBuffer, AF_INET6, newIp, isDefaultRoute); @@ -157,6 +173,8 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) result->speed = (int32_t) (adapter->ReceiveLinkSpeed / 1000); if (options->showType & FF_LOCALIP_TYPE_MTU_BIT) result->mtu = (int32_t) adapter->Mtu; + if (options->showType & FF_LOCALIP_TYPE_FLAGS_BIT) + ffLocalIpFillNIFlags(&result->flags, adapter->Flags, niFlagOptions); } } diff --git a/src/detection/memory/memory_nosupport.c b/src/detection/memory/memory_nosupport.c index 76cd7f8282..180a276aac 100644 --- a/src/detection/memory/memory_nosupport.c +++ b/src/detection/memory/memory_nosupport.c @@ -1,6 +1,6 @@ #include "memory.h" -const char* ffDetectMemory(FFMemoryResult* ram) +const char* ffDetectMemory(FF_MAYBE_UNUSED FFMemoryResult* ram) { return "Not supported on this platform"; } diff --git a/src/detection/memory/memory_obsd.c b/src/detection/memory/memory_obsd.c new file mode 100644 index 0000000000..9efc21ead9 --- /dev/null +++ b/src/detection/memory/memory_obsd.c @@ -0,0 +1,17 @@ +#include "memory.h" +#include "common/sysctl.h" + +#include + +const char* ffDetectMemory(FFMemoryResult* ram) +{ + struct uvmexp buf; + size_t length = sizeof(buf); + if (sysctl((int[]){ CTL_VM, VM_UVMEXP }, 2, &buf, &length, NULL, 0) < 0) + return "sysctl(CTL_VM, VM_UVMEXP) failed"; + + ram->bytesTotal = (uint64_t) buf.npages * instance.state.platform.sysinfo.pageSize; + ram->bytesUsed = ram->bytesTotal - (uint64_t) buf.free * instance.state.platform.sysinfo.pageSize; + + return NULL; +} diff --git a/src/detection/memory/memory_sunos.c b/src/detection/memory/memory_sunos.c index 4633eb6c07..1df271055d 100644 --- a/src/detection/memory/memory_sunos.c +++ b/src/detection/memory/memory_sunos.c @@ -1,34 +1,10 @@ #include "memory.h" -#include - -static inline void kstatFreeWrap(kstat_ctl_t** pkc) -{ - assert(pkc); - if (*pkc) - kstat_close(*pkc); -} +#include const char* ffDetectMemory(FFMemoryResult* ram) { - __attribute__((__cleanup__(kstatFreeWrap))) kstat_ctl_t* kc = kstat_open(); - if (!kc) - return "kstat_open() failed"; - - kstat_t* ks = kstat_lookup(kc, "unix", -1, "system_pages"); - if (!ks) - return "kstat_lookup() failed"; - - if (kstat_read(kc, ks, NULL) < 0) - return "kstat_read() failed"; - - { - kstat_named_t* kn = kstat_data_lookup(ks, "pagestotal"); - ram->bytesTotal = kn->value.ui64 * instance.state.platform.sysinfo.pageSize; - } - { - kstat_named_t* kn = kstat_data_lookup(ks, "pagesfree"); - ram->bytesUsed = ram->bytesTotal - kn->value.ui64 * instance.state.platform.sysinfo.pageSize; - } + ram->bytesTotal = sysconf(_SC_PHYS_PAGES) * instance.state.platform.sysinfo.pageSize; + ram->bytesUsed = ram->bytesTotal - sysconf(_SC_AVPHYS_PAGES) * instance.state.platform.sysinfo.pageSize; return NULL; } diff --git a/src/detection/mouse/mouse.h b/src/detection/mouse/mouse.h new file mode 100644 index 0000000000..710b4f8dff --- /dev/null +++ b/src/detection/mouse/mouse.h @@ -0,0 +1,9 @@ +#include "fastfetch.h" + +typedef struct FFMouseDevice +{ + FFstrbuf serial; + FFstrbuf name; +} FFMouseDevice; + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */); diff --git a/src/detection/mouse/mouse_apple.c b/src/detection/mouse/mouse_apple.c new file mode 100644 index 0000000000..feadff649a --- /dev/null +++ b/src/detection/mouse/mouse_apple.c @@ -0,0 +1,42 @@ +#include "mouse.h" +#include "util/apple/cf_helpers.h" +#include "util/mallocHelper.h" + +#include +#include + +static void enumSet(IOHIDDeviceRef value, FFlist* results) +{ + FFMouseDevice* device = (FFMouseDevice*) ffListAdd(results); + ffStrbufInit(&device->serial); + ffStrbufInit(&device->name); + + CFStringRef product = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDProductKey)); + ffCfStrGetString(product, &device->name); + + CFStringRef serialNumber = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDSerialNumberKey)); + ffCfStrGetString(serialNumber, &device->serial); +} + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) +{ + IOHIDManagerRef FF_CFTYPE_AUTO_RELEASE manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); + if (IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) + return "IOHIDManagerOpen() failed"; + + CFDictionaryRef FF_CFTYPE_AUTO_RELEASE matching1 = CFDictionaryCreate(kCFAllocatorDefault, (const void **)(CFStringRef[]){ + CFSTR(kIOHIDDeviceUsagePageKey), + CFSTR(kIOHIDDeviceUsageKey) + }, (const void **)(CFNumberRef[]){ + ffCfCreateInt(kHIDPage_GenericDesktop), + ffCfCreateInt(kHIDUsage_GD_Mouse) + }, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + IOHIDManagerSetDeviceMatching(manager, matching1); + + CFSetRef FF_CFTYPE_AUTO_RELEASE set = IOHIDManagerCopyDevices(manager); + if (set) + CFSetApplyFunction(set, (CFSetApplierFunction) &enumSet, devices); + IOHIDManagerClose(manager, kIOHIDOptionsTypeNone); + + return NULL; +} diff --git a/src/detection/mouse/mouse_bsd.c b/src/detection/mouse/mouse_bsd.c new file mode 100644 index 0000000000..ec978974be --- /dev/null +++ b/src/detection/mouse/mouse_bsd.c @@ -0,0 +1,47 @@ +#include "mouse.h" +#include "common/io/io.h" + +#include +#include +#include +#include + +#define MAX_UHID_JOYS 64 + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) +{ + char path[16]; + for (int i = 0; i < MAX_UHID_JOYS; i++) + { + snprintf(path, sizeof(path), "/dev/uhid%d", i); + FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); + if (fd < 0) continue; + + report_desc_t repDesc = hid_get_report_desc(fd); + if (!repDesc) continue; + + int reportId = hid_get_report_id(fd); + + struct hid_data* hData = hid_start_parse(repDesc, 0, reportId); + if (hData) + { + struct hid_item hItem; + while (hid_get_item(hData, &hItem) > 0) + { + if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 2) continue; + + struct usb_device_info di; + if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1) + { + FFMouseDevice* device = (FFMouseDevice*) ffListAdd(devices); + ffStrbufInitS(&device->serial, di.udi_serial); + ffStrbufInitS(&device->name, di.udi_product); + } + } + } + + hid_dispose_report_desc(repDesc); + } + + return NULL; +} diff --git a/src/detection/mouse/mouse_linux.c b/src/detection/mouse/mouse_linux.c new file mode 100644 index 0000000000..d03a3e7e57 --- /dev/null +++ b/src/detection/mouse/mouse_linux.c @@ -0,0 +1,44 @@ +#include "mouse.h" +#include "common/io/io.h" +#include "util/stringUtils.h" + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) +{ + FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/input/"); + if (dirp == NULL) + return "opendir(\"/sys/class/input/\") == NULL"; + + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/class/input/"); + uint32_t baseLen = path.length; + + struct dirent* entry; + while ((entry = readdir(dirp)) != NULL) + { + if (!ffStrStartsWith(entry->d_name, "mouse")) + continue; + if (!ffCharIsDigit(entry->d_name[strlen("mouse")])) + continue; + + ffStrbufAppendS(&path, entry->d_name); + ffStrbufAppendS(&path, "/device/name"); + + FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate(); + if (ffAppendFileBuffer(path.chars, &name)) + { + ffStrbufTrimRightSpace(&name); + ffStrbufSubstrBefore(&path, path.length - 4); + + FFMouseDevice* device = (FFMouseDevice*) ffListAdd(devices); + ffStrbufInitMove(&device->name, &name); + ffStrbufInit(&device->serial); + + ffStrbufAppendS(&path, "uniq"); + if (ffAppendFileBuffer(path.chars, &device->serial)) + ffStrbufTrimRightSpace(&device->serial); + } + + ffStrbufSubstrBefore(&path, baseLen); + } + + return NULL; +} diff --git a/src/detection/mouse/mouse_nosupport.c b/src/detection/mouse/mouse_nosupport.c new file mode 100644 index 0000000000..ba5a6c157b --- /dev/null +++ b/src/detection/mouse/mouse_nosupport.c @@ -0,0 +1,6 @@ +#include "mouse.h" + +const char* ffDetectMouse(FF_MAYBE_UNUSED FFlist* devices /* List of FFMouseDevice */) +{ + return "No mouse support on this platform"; +} diff --git a/src/detection/mouse/mouse_windows.c b/src/detection/mouse/mouse_windows.c new file mode 100644 index 0000000000..094390d35c --- /dev/null +++ b/src/detection/mouse/mouse_windows.c @@ -0,0 +1,89 @@ +#define INITGUID + +#include "mouse.h" +#include "common/io/io.h" +#include "util/mallocHelper.h" +#include "util/windows/unicode.h" + +#include +#include +#include +#include +#include + +WINAPI CMAPI CONFIGRET CM_Get_Device_Interface_PropertyW( + _In_ LPCWSTR pszDeviceInterface, + _In_ const DEVPROPKEY *PropertyKey, + _Out_ DEVPROPTYPE *PropertyType, + _Out_ PBYTE PropertyBuffer, + _Inout_ PULONG PropertyBufferSize, + _In_ ULONG ulFlags +); + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) +{ + UINT nDevices = 0; + if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST))) + return "GetRawInputDeviceList(NULL) failed"; + if (nDevices == 0) + return "No HID devices found"; + RAWINPUTDEVICELIST* FF_AUTO_FREE pRawInputDeviceList = (RAWINPUTDEVICELIST*) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); + if ((nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == (UINT) -1) + return "GetRawInputDeviceList(pRawInputDeviceList) failed"; + + for (UINT i = 0; i < nDevices; ++i) + { + if (pRawInputDeviceList[i].dwType != RIM_TYPEMOUSE) continue; + + HANDLE hDevice = pRawInputDeviceList[i].hDevice; + + RID_DEVICE_INFO rdi; + UINT rdiSize = sizeof(rdi); + if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) == (UINT) -1) + continue; + + WCHAR devName[MAX_PATH]; + UINT nameSize = MAX_PATH; + if (GetRawInputDeviceInfoW(hDevice, RIDI_DEVICENAME, devName, &nameSize) == (UINT) -1) + continue; + + FFMouseDevice* device = (FFMouseDevice*) ffListAdd(devices); + ffStrbufInit(&device->serial); + ffStrbufInit(&device->name); + + wchar_t buffer[MAX_PATH]; + + HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, 0 /* must be 0 instead of GENERIC_READ */, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (hHidFile != INVALID_HANDLE_VALUE) + { + if (HidD_GetProductString(hHidFile, buffer, (ULONG) sizeof(buffer))) + ffStrbufSetWS(&device->name, buffer); + + if (HidD_GetSerialNumberString(hHidFile, buffer, sizeof(buffer))) + ffStrbufSetWS(&device->serial, buffer); + } + + if (!device->name.length) + { + // https://stackoverflow.com/a/64321096/9976392 + DEVPROPTYPE propertyType; + ULONG propertySize = sizeof(buffer); + + if (CM_Get_Device_Interface_PropertyW(devName, &DEVPKEY_Device_InstanceId, &propertyType, (PBYTE) buffer, &propertySize, 0) == CR_SUCCESS) + { + DEVINST devInst; + if (CM_Locate_DevNodeW(&devInst, buffer, CM_LOCATE_DEVNODE_NORMAL) == CR_SUCCESS) + { + propertySize = sizeof(buffer); + if (CM_Get_DevNode_PropertyW(devInst, &DEVPKEY_NAME, &propertyType, (PBYTE) buffer, &propertySize, 0) == CR_SUCCESS) + ffStrbufSetWS(&device->name, buffer); + } + } + } + + if (!device->name.length) + ffStrbufSetF(&device->name, "Unknown device %04X-%04X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId); + } + + return NULL; +} diff --git a/src/detection/netio/netio_nosupport.c b/src/detection/netio/netio_nosupport.c index 254f228605..be9a30b6cb 100644 --- a/src/detection/netio/netio_nosupport.c +++ b/src/detection/netio/netio_nosupport.c @@ -1,6 +1,6 @@ #include "netio.h" -const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) +const char* ffNetIOGetIoCounters(FF_MAYBE_UNUSED FFlist* result, FF_MAYBE_UNUSED FFNetIOOptions* options) { return "Not supported on this platform"; } diff --git a/src/detection/opencl/opencl.c b/src/detection/opencl/opencl.c index cb51762570..71e89a36eb 100644 --- a/src/detection/opencl/opencl.c +++ b/src/detection/opencl/opencl.c @@ -15,8 +15,10 @@ #define CL_TARGET_OPENCL_VERSION 110 #ifndef __APPLE__ #include + #include #else #include + #include #endif typedef struct OpenCLData @@ -31,8 +33,23 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result) { cl_platform_id platforms[32]; cl_uint numPlatforms = 0; - if (data->ffclGetPlatformIDs(sizeof(platforms) / sizeof(platforms[0]), platforms, &numPlatforms) != CL_SUCCESS) - return "clGetPlatformIDs() failed"; + cl_int ret = data->ffclGetPlatformIDs(sizeof(platforms) / sizeof(platforms[0]), platforms, &numPlatforms); + if (ret != CL_SUCCESS) + { + switch (ret) + { + #ifdef CL_PLATFORM_NOT_FOUND_KHR // not available on macOS + case CL_PLATFORM_NOT_FOUND_KHR: + return "clGetPlatformIDs() failed: CL_PLATFORM_NOT_FOUND_KHR"; + #endif + case CL_INVALID_VALUE: + return "clGetPlatformIDs() failed: CL_INVALID_VALUE"; + case CL_OUT_OF_HOST_MEMORY: + return "clGetPlatformIDs() failed: CL_OUT_OF_HOST_MEMORY"; + default: + return "clGetPlatformIDs() failed: unknown error"; + } + } if (numPlatforms == 0) return "clGetPlatformIDs returned 0 platforms"; diff --git a/src/detection/opengl/opengl_linux.c b/src/detection/opengl/opengl_linux.c index 051107bece..05a72bf25c 100644 --- a/src/detection/opengl/opengl_linux.c +++ b/src/detection/opengl/opengl_linux.c @@ -14,7 +14,6 @@ void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglG #endif // FF_HAVE_GL - #ifdef FF_HAVE_GLX #include @@ -25,7 +24,7 @@ typedef struct GLXData FF_LIBRARY_SYMBOL(glXQueryVersion) FF_LIBRARY_SYMBOL(XOpenDisplay) FF_LIBRARY_SYMBOL(glXChooseVisual) - FF_LIBRARY_SYMBOL(XCreatePixmap); + FF_LIBRARY_SYMBOL(XCreatePixmap) FF_LIBRARY_SYMBOL(glXCreateGLXPixmap) FF_LIBRARY_SYMBOL(glXCreateContext) FF_LIBRARY_SYMBOL(glXMakeCurrent) @@ -120,7 +119,13 @@ static const char* detectByGlx(FFOpenGLResult* result) { GLXData data; - FF_LIBRARY_LOAD(glx, "dlopen glx failed", "libGLX" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_LOAD(glx, "dlopen glx failed", + #if !__OpenBSD__ + "libGLX" + #else + "libGL" + #endif + FF_LIBRARY_EXTENSION, 1); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXGetProcAddress); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXQueryVersion); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XOpenDisplay); diff --git a/src/detection/os/os_obsd.c b/src/detection/os/os_obsd.c new file mode 100644 index 0000000000..10a0bfd812 --- /dev/null +++ b/src/detection/os/os_obsd.c @@ -0,0 +1,7 @@ +#include "os.h" + +void ffDetectOSImpl(FFOSResult* os) +{ + ffStrbufSetStatic(&os->name, "OpenBSD"); + ffStrbufSet(&os->version, &instance.state.platform.sysinfo.release); +} diff --git a/src/detection/packages/packages_bsd.c b/src/detection/packages/packages_bsd.c index 8212229270..511af569b1 100644 --- a/src/detection/packages/packages_bsd.c +++ b/src/detection/packages/packages_bsd.c @@ -18,7 +18,7 @@ static uint32_t getSQLite3Int(const char* dbPath, const char* query, const char* return num_elements; } -void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options) +void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) { if (!(options->disabled & FF_PACKAGES_FLAG_PKG_BIT)) { diff --git a/src/detection/packages/packages_nosupport.c b/src/detection/packages/packages_nosupport.c index 87f65a8ebe..a6d9a7b904 100644 --- a/src/detection/packages/packages_nosupport.c +++ b/src/detection/packages/packages_nosupport.c @@ -1,5 +1,5 @@ #include "packages.h" -void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) +void ffDetectPackagesImpl(FF_MAYBE_UNUSED FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options) { } diff --git a/src/detection/packages/packages_obsd.c b/src/detection/packages/packages_obsd.c new file mode 100644 index 0000000000..c7fadcbdff --- /dev/null +++ b/src/detection/packages/packages_obsd.c @@ -0,0 +1,31 @@ +#include "packages.h" + +#include "common/io/io.h" + +static uint32_t getNumElementsImpl(const char* dirname, unsigned char type) +{ + FF_AUTO_CLOSE_DIR DIR* dirp = opendir(dirname); + if(dirp == NULL) + return 0; + + uint32_t num_elements = 0; + + struct dirent *entry; + while((entry = readdir(dirp)) != NULL) { + if(entry->d_type == type) + ++num_elements; + } + + if(type == DT_DIR && num_elements >= 2) + num_elements -= 2; // accounting for . and .. + + return num_elements; +} + +void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) +{ + if (!(options->disabled & FF_PACKAGES_FLAG_PKG_BIT)) + { + result->pkg = getNumElementsImpl(FASTFETCH_TARGET_DIR_ROOT "/var/db/pkg", DT_DIR); + } +} diff --git a/src/detection/physicaldisk/physicaldisk_linux.c b/src/detection/physicaldisk/physicaldisk_linux.c index 1b12d70fbc..266a37218c 100644 --- a/src/detection/physicaldisk/physicaldisk_linux.c +++ b/src/detection/physicaldisk/physicaldisk_linux.c @@ -5,19 +5,18 @@ #include #include +#include +#include -static double detectNvmeTemp(const char* devName) +static double detectNvmeTemp(int devfd) { - char pathSysBlock[PATH_MAX]; - int index = snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/hwmon$/temp1_input", devName); - if (index <= 0) return FF_PHYSICALDISK_TEMP_UNSET; - index -= (int) sizeof("/temp1_input"); + char pathHwmon[] = "hwmon$/temp1_input"; for (char c = '0'; c <= '9'; c++) // hopefully there's only one digit { - pathSysBlock[index] = c; + pathHwmon[strlen("hwmon")] = c; char buffer[64]; - ssize_t size = ffReadFileData(pathSysBlock, sizeof(buffer), buffer); + ssize_t size = ffReadFileDataRelative(devfd, pathHwmon, sizeof(buffer), buffer); if (size > 0) { buffer[size] = '\0'; @@ -29,160 +28,154 @@ static double detectNvmeTemp(const char* devName) return FF_PHYSICALDISK_TEMP_UNSET; } -const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) +static void parsePhysicalDisk(int dfd, const char* devName, const char* pathSysDeviceReal, FFPhysicalDiskOptions* options, FFlist* result) { - FF_AUTO_CLOSE_DIR DIR* sysBlockDirp = opendir("/sys/block/"); - if(sysBlockDirp == NULL) - return "opendir(\"/sys/block/\") == NULL"; - - struct dirent* sysBlockEntry; - while ((sysBlockEntry = readdir(sysBlockDirp)) != NULL) - { - const char* const devName = sysBlockEntry->d_name; - - if (devName[0] == '.') - continue; + int devfd = openat(dfd, "device", O_RDONLY | O_CLOEXEC); + if (devfd < 0) return; - char pathSysBlock[PATH_MAX]; - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s", devName); + FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate(); - char pathSysDeviceReal[PATH_MAX]; - ssize_t pathLength = readlink(pathSysBlock, pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1); - if (pathLength < 0) - continue; - pathSysDeviceReal[pathLength] = '\0'; - - if (strstr(pathSysDeviceReal, "/virtual/")) // virtual device - continue; + { + if (ffAppendFileBufferRelative(devfd, "vendor", &name)) + { + ffStrbufTrimRightSpace(&name); + if (name.length > 0) + ffStrbufAppendC(&name, ' '); + } - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device", devName); - if (!ffPathExists(pathSysBlock, FF_PATHTYPE_DIRECTORY)) - continue; + ffAppendFileBufferRelative(devfd, "model", &name); + ffStrbufTrimRightSpace(&name); - FFPhysicalDiskResult* device = (FFPhysicalDiskResult*) ffListAdd(result); - device->type = FF_PHYSICALDISK_TYPE_NONE; - ffStrbufInit(&device->name); + if (name.length == 0) + ffStrbufSetS(&name, devName); + if (ffStrStartsWith(devName, "nvme")) { - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/vendor", devName); - if (ffAppendFileBuffer(pathSysBlock, &device->name)) + int devid, nsid; + if (sscanf(devName, "nvme%dn%d", &devid, &nsid) == 2) { - ffStrbufTrimRightSpace(&device->name); - if (device->name.length > 0) - ffStrbufAppendC(&device->name, ' '); - } - - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/model", devName); - ffAppendFileBuffer(pathSysBlock, &device->name); - ffStrbufTrimRightSpace(&device->name); - - if (device->name.length == 0) - ffStrbufSetS(&device->name, devName); - else if (ffStrStartsWith(devName, "nvme")) - { - int devid, nsid; - if (sscanf(devName, "nvme%dn%d", &devid, &nsid) == 2) + bool multiNs = nsid > 1; + if (!multiNs) { - bool multiNs = nsid > 1; - if (!multiNs) - { - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/nvme%dn2", devName, devid); - multiNs = ffPathExists(pathSysBlock, FF_PATHTYPE_DIRECTORY); - } - if (multiNs) - { - // In Asahi Linux, there are multiple namespaces for the same NVMe drive. - ffStrbufAppendF(&device->name, " - %d", nsid); - } + char pathSysBlock[32]; + snprintf(pathSysBlock, sizeof(pathSysBlock), "/dev/nvme%dn2", devid); + multiNs = access(pathSysBlock, F_OK) == 0; + } + if (multiNs) + { + // In Asahi Linux, there are multiple namespaces for the same NVMe drive. + ffStrbufAppendF(&name, " - %d", nsid); } - } - - if (options->namePrefix.length && !ffStrbufStartsWith(&device->name, &options->namePrefix)) - { - ffStrbufDestroy(&device->name); - result->length--; - continue; } } - ffStrbufInitF(&device->devPath, "/dev/%s", devName); + if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix)) + return; + } - { - ffStrbufInit(&device->interconnect); - if (strstr(pathSysDeviceReal, "/usb") != NULL) - ffStrbufSetS(&device->interconnect, "USB"); - else if (strstr(pathSysDeviceReal, "/nvme") != NULL) - ffStrbufSetS(&device->interconnect, "NVMe"); - else if (strstr(pathSysDeviceReal, "/ata") != NULL) - ffStrbufSetS(&device->interconnect, "ATA"); - else if (strstr(pathSysDeviceReal, "/scsi") != NULL) - ffStrbufSetS(&device->interconnect, "SCSI"); - else - { - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/transport", devName); - if (ffAppendFileBuffer(pathSysBlock, &device->interconnect)) - ffStrbufTrimRightSpace(&device->interconnect); - } - } + FFPhysicalDiskResult* device = (FFPhysicalDiskResult*) ffListAdd(result); + device->type = FF_PHYSICALDISK_TYPE_NONE; + ffStrbufInitMove(&device->name, &name); + ffStrbufInitF(&device->devPath, "/dev/%s", devName); + { + ffStrbufInit(&device->interconnect); + if (strstr(pathSysDeviceReal, "/usb") != NULL) + ffStrbufSetS(&device->interconnect, "USB"); + else if (strstr(pathSysDeviceReal, "/nvme") != NULL) + ffStrbufSetS(&device->interconnect, "NVMe"); + else if (strstr(pathSysDeviceReal, "/ata") != NULL) + ffStrbufSetS(&device->interconnect, "ATA"); + else if (strstr(pathSysDeviceReal, "/scsi") != NULL) + ffStrbufSetS(&device->interconnect, "SCSI"); + else { - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/queue/rotational", devName); - char isRotationalChar = '1'; - if (ffReadFileData(pathSysBlock, 1, &isRotationalChar) > 0) - device->type |= isRotationalChar == '1' ? FF_PHYSICALDISK_TYPE_HDD : FF_PHYSICALDISK_TYPE_SSD; + if (ffAppendFileBufferRelative(devfd, "transport", &device->interconnect)) + ffStrbufTrimRightSpace(&device->interconnect); } + } - { - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/size", devName); - char blkSize[32]; - ssize_t fileSize = ffReadFileData(pathSysBlock, sizeof(blkSize) - 1, blkSize); - if (fileSize > 0) - { - blkSize[fileSize] = 0; - device->size = (uint64_t) strtoul(blkSize, NULL, 10) * 512; - } - else - device->size = 0; - } + { + char isRotationalChar = '1'; + if (ffReadFileDataRelative(dfd, "queue/rotational", 1, &isRotationalChar) > 0) + device->type |= isRotationalChar == '1' ? FF_PHYSICALDISK_TYPE_HDD : FF_PHYSICALDISK_TYPE_SSD; + } + { + char blkSize[32]; + ssize_t fileSize = ffReadFileDataRelative(dfd, "size", sizeof(blkSize) - 1, blkSize); + if (fileSize > 0) { - char removableChar = '0'; - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/removable", devName); - if (ffReadFileData(pathSysBlock, 1, &removableChar) > 0) - device->type |= removableChar == '1' ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED; + blkSize[fileSize] = 0; + device->size = (uint64_t) strtoul(blkSize, NULL, 10) * 512; } + else + device->size = 0; + } - { - char roChar = '0'; - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/ro", devName); - if (ffReadFileData(pathSysBlock, 1, &roChar) > 0) - device->type |= roChar == '1' ? FF_PHYSICALDISK_TYPE_READONLY : FF_PHYSICALDISK_TYPE_READWRITE; - } + { + char removableChar = '0'; + if (ffReadFileDataRelative(dfd, "removable", 1, &removableChar) > 0) + device->type |= removableChar == '1' ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED; + } - { - ffStrbufInit(&device->serial); - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/serial", devName); - if (ffReadFileBuffer(pathSysBlock, &device->serial)) - ffStrbufTrimRightSpace(&device->serial); - } + { + char roChar = '0'; + if (ffReadFileDataRelative(dfd, "ro", 1, &roChar) > 0) + device->type |= roChar == '1' ? FF_PHYSICALDISK_TYPE_READONLY : FF_PHYSICALDISK_TYPE_READWRITE; + } + { + ffStrbufInit(&device->serial); + if (ffReadFileBufferRelative(devfd, "serial", &device->serial)) + ffStrbufTrimRightSpace(&device->serial); + } + + { + ffStrbufInit(&device->revision); + if (ffReadFileBufferRelative(devfd, "firmware_rev", &device->revision)) + ffStrbufTrimRightSpace(&device->revision); + else { - ffStrbufInit(&device->revision); - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/firmware_rev", devName); - if (ffReadFileBuffer(pathSysBlock, &device->revision)) + if (ffReadFileBufferRelative(devfd, "rev", &device->revision)) ffStrbufTrimRightSpace(&device->revision); - else - { - snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/rev", devName); - if (ffReadFileBuffer(pathSysBlock, &device->revision)) - ffStrbufTrimRightSpace(&device->revision); - } } + } - if (options->temp) - device->temperature = detectNvmeTemp(devName); - else - device->temperature = FF_PHYSICALDISK_TEMP_UNSET; + if (options->temp) + device->temperature = detectNvmeTemp(devfd); + else + device->temperature = FF_PHYSICALDISK_TEMP_UNSET; +} + +const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) +{ + FF_AUTO_CLOSE_DIR DIR* sysBlockDirp = opendir("/sys/block/"); + if(sysBlockDirp == NULL) + return "opendir(\"/sys/block/\") == NULL"; + + struct dirent* sysBlockEntry; + while ((sysBlockEntry = readdir(sysBlockDirp)) != NULL) + { + const char* const devName = sysBlockEntry->d_name; + + if (devName[0] == '.') + continue; + + char pathSysBlock[sizeof("/sys/block/") + sizeof(sysBlockEntry->d_name)]; + snprintf(pathSysBlock, sizeof(pathSysBlock), "/sys/block/%s", devName); + + char pathSysDeviceReal[PATH_MAX]; + ssize_t pathLength = readlink(pathSysBlock, pathSysDeviceReal, sizeof(pathSysDeviceReal) - 1); + if (pathLength < 0) + continue; + pathSysDeviceReal[pathLength] = '\0'; + + if (strstr(pathSysDeviceReal, "/virtual/")) // virtual device + continue; + + int dfd = openat(dirfd(sysBlockDirp), devName, O_RDONLY | O_CLOEXEC); + if (dfd > 0) parsePhysicalDisk(dfd, devName, pathSysDeviceReal, options, result); } return NULL; diff --git a/src/detection/poweradapter/poweradapter_linux.c b/src/detection/poweradapter/poweradapter_linux.c index 5c5a3f9972..839b687b03 100644 --- a/src/detection/poweradapter/poweradapter_linux.c +++ b/src/detection/poweradapter/poweradapter_linux.c @@ -3,46 +3,37 @@ #include "util/stringUtils.h" #include +#include +#include -static void parsePowerAdapter(FFstrbuf* dir, FF_MAYBE_UNUSED const char* id, FFlist* results) +static void parsePowerAdapter(int dfd, FF_MAYBE_UNUSED const char* id, FFlist* results) { - uint32_t dirLength = dir->length; - FF_STRBUF_AUTO_DESTROY tmpBuffer = ffStrbufCreate(); //type must exist and be "Mains" - ffStrbufAppendS(dir, "/type"); - if (ffReadFileBuffer(dir->chars, &tmpBuffer)) + if (ffReadFileBufferRelative(dfd, "type", &tmpBuffer)) ffStrbufTrimRightSpace(&tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); if(!ffStrbufIgnCaseEqualS(&tmpBuffer, "Mains")) return; //scope may not exist or must not be "Device" (?) - ffStrbufAppendS(dir, "/scope"); - if (ffReadFileBuffer(dir->chars, &tmpBuffer)) + if (ffReadFileBufferRelative(dfd, "scope", &tmpBuffer)) ffStrbufTrimRightSpace(&tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseEqualS(&tmpBuffer, "Device")) return; - ffStrbufAppendS(dir, "/online"); - char online = '1'; - ffReadFileData(dir->chars, sizeof(online), &online); - ffStrbufSubstrBefore(dir, dirLength); + char online = '\0'; + ffReadFileDataRelative(dfd, "online", sizeof(online), &online); - if (online == '0') + if (online != '1') return; //input_power_limit must exist and be not empty - ffStrbufAppendS(dir, "/input_power_limit"); - bool available = ffReadFileBuffer(dir->chars, &tmpBuffer); - ffStrbufSubstrBefore(dir, dirLength); - - if (!available) + if (!ffReadFileBufferRelative(dfd, "input_power_limit", &tmpBuffer)) return; + FFPowerAdapterResult* result = ffListAdd(results); ffStrbufInit(&result->name); ffStrbufInit(&result->description); @@ -51,32 +42,21 @@ static void parsePowerAdapter(FFstrbuf* dir, FF_MAYBE_UNUSED const char* id, FFl ffStrbufInit(&result->modelName); ffStrbufInit(&result->serial); - ffStrbufAppendS(dir, "/manufacturer"); - if (ffReadFileBuffer(dir->chars, &result->manufacturer)) + if (ffReadFileBufferRelative(dfd, "manufacturer", &result->manufacturer)) ffStrbufTrimRightSpace(&result->manufacturer); else if (ffStrEquals(id, "macsmc-ac")) // asahi ffStrbufSetStatic(&result->manufacturer, "Apple Inc."); - ffStrbufSubstrBefore(dir, dirLength); - ffStrbufAppendS(dir, "/model_name"); - if (ffReadFileBuffer(dir->chars, &result->modelName)) + if (ffReadFileBufferRelative(dfd, "model_name", &result->modelName)) ffStrbufTrimRightSpace(&result->modelName); - ffStrbufSubstrBefore(dir, dirLength); - ffStrbufAppendS(dir, "/serial_number"); - if (ffReadFileBuffer(dir->chars, &result->serial)) + if (ffReadFileBufferRelative(dfd, "serial_number", &result->serial)) ffStrbufTrimRightSpace(&result->serial); - ffStrbufSubstrBefore(dir, dirLength); } const char* ffDetectPowerAdapter(FFlist* results) { - FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64); - ffStrbufAppendS(&baseDir, "/sys/class/power_supply/"); - - uint32_t baseDirLength = baseDir.length; - - FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir.chars); + FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/power_supply/"); if(dirp == NULL) return "opendir(\"/sys/class/power_supply/\") == NULL"; @@ -86,9 +66,8 @@ const char* ffDetectPowerAdapter(FFlist* results) if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, "..")) continue; - ffStrbufAppendS(&baseDir, entry->d_name); - parsePowerAdapter(&baseDir, entry->d_name, results); - ffStrbufSubstrBefore(&baseDir, baseDirLength); + FF_AUTO_CLOSE_FD int dfd = openat(dirfd(dirp), entry->d_name, O_RDONLY | O_CLOEXEC); + if (dfd > 0) parsePowerAdapter(dfd, entry->d_name, results); } return NULL; diff --git a/src/detection/processes/processes_obsd.c b/src/detection/processes/processes_obsd.c new file mode 100644 index 0000000000..75db1c4d09 --- /dev/null +++ b/src/detection/processes/processes_obsd.c @@ -0,0 +1,14 @@ +#include "processes.h" + +#include +#include +#include + +const char* ffDetectProcesses(uint32_t* result) +{ + kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL); + const void* ret = kvm_getprocs(kd, KERN_PROC_ALL, 0, 1, result); + kvm_close(kd); + if (!ret) return "kvm_getprocs() failed"; + return NULL; +} diff --git a/src/detection/swap/swap_obsd.c b/src/detection/swap/swap_obsd.c new file mode 100644 index 0000000000..b64900c9fa --- /dev/null +++ b/src/detection/swap/swap_obsd.c @@ -0,0 +1,30 @@ +#include "swap.h" +#include "util/mallocHelper.h" + +#include +#include +#include +#include + +const char* ffDetectSwap(FFSwapResult* swap) +{ + int nswap = swapctl(SWAP_NSWAP, 0, 0); + if (nswap < 0) return "swapctl(SWAP_NSWAP) failed"; + if (nswap == 0) NULL; + + struct swapent* swdev = malloc((uint32_t) nswap * sizeof(*swdev)); + + if (swapctl(SWAP_STATS, swdev, nswap) < 0) + return "swapctl(SWAP_STATS) failed"; + + for (int i = 0; i < nswap; i++) + { + if (swdev[i].se_flags & SWF_ENABLE) + { + swap->bytesUsed += (uint64_t) swdev[i].se_inuse * DEV_BSIZE; + swap->bytesTotal += (uint64_t) swdev[i].se_nblks * DEV_BSIZE; + } + } + + return NULL; +} diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index e992f78929..c933937bf9 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -82,7 +82,7 @@ FF_MAYBE_UNUSED static bool detectKitty(const FFstrbuf* exe, FFTerminalFontResul if (ffGetTerminalResponse( "\eP+q6b697474792d71756572792d666f6e745f66616d696c79;6b697474792d71756572792d666f6e745f73697a65\e\\", // kitty-query-font_family;kitty-query-font_size 2, - "\eP1+r%*[^=]=%512[^\e]\e\\\eP1+r%*[^=]=%512[^\e]\e\\", fontHex, sizeHex) == NULL && *fontHex && *sizeHex) + "\eP1+r%*[^=]=%511[^\e]\e\\\eP1+r%*[^=]=%511[^\e]\e\\", fontHex, sizeHex) == NULL && *fontHex && *sizeHex) { // decode hex string for (const char* p = fontHex; p[0] && p[1]; p += 2) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 4280f20df2..45e4bb75f9 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -8,6 +8,8 @@ #include #ifdef __FreeBSD__ #include +#elif __OpenBSD__ + #define _PATH_LOCALBASE "/usr/local" #endif #ifdef _WIN32 @@ -119,6 +121,19 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version) static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version) { +#if __OpenBSD__ + if(ffProcessAppendStdOut(version, (char* const[]) { + exe->chars, + "-c", + "echo $KSH_VERSION", + NULL + }) != NULL) + return false; + + // @(#)PD KSH v5.2.14 99/07/13.2 + ffStrbufSubstrAfterFirstC(version, 'v'); + ffStrbufSubstrBeforeFirstC(version, ' '); +#else if(ffProcessAppendStdErr(version, (char* const[]) { exe->chars, "--version", @@ -129,6 +144,7 @@ static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version) // version sh (AT&T Research) 93u+ 2012-08-01 ffStrbufSubstrAfterLastC(version, ')'); ffStrbufTrim(version, ' '); +#endif return true; } @@ -559,7 +575,7 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version) #ifndef _WIN32 static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) { - #if defined(__linux__) || defined(__FreeBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) char buffer[1024] = {}; if ( #ifdef __linux__ @@ -662,7 +678,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe #endif - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) if(ffStrbufStartsWithIgnCaseS(processName, "gnome-terminal")) return getTerminalVersionGnome(exe, version); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 0355e25636..c29d97742d 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -161,23 +161,30 @@ static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv static void getTerminalFromEnv(FFTerminalResult* result) { - if( - result->processName.length > 0 && - !ffStrbufStartsWithS(&result->processName, "login") && - !ffStrbufEqualS(&result->processName, "(login)") && + if (result->processName.length > 0) + { + if (!ffStrbufStartsWithS(&result->processName, "login") && + !ffStrbufEqualS(&result->processName, "(login)") && + + #ifdef __APPLE__ + !ffStrbufEqualS(&result->processName, "launchd") && + !ffStrbufEqualS(&result->processName, "stable") && //for WarpTerminal + #else + !ffStrbufEqualS(&result->processName, "systemd") && + !ffStrbufEqualS(&result->processName, "init") && + !ffStrbufEqualS(&result->processName, "(init)") && + !ffStrbufEqualS(&result->processName, "SessionLeader") && // #750 + #endif - #ifdef __APPLE__ - !ffStrbufEqualS(&result->processName, "launchd") && - !ffStrbufEqualS(&result->processName, "stable") && //for WarpTerminal - #else - !ffStrbufEqualS(&result->processName, "systemd") && - !ffStrbufEqualS(&result->processName, "init") && - !ffStrbufEqualS(&result->processName, "(init)") && - !ffStrbufEqualS(&result->processName, "SessionLeader") && // #750 - #endif + !ffStrbufEqualS(&result->processName, "0") + ) return; - !ffStrbufEqualS(&result->processName, "0") - ) return; + ffStrbufClear(&result->processName); + ffStrbufClear(&result->exe); + result->exeName = result->exe.chars; + ffStrbufClear(&result->exePath); + result->pid = result->ppid = 0; + } const char* term = NULL; diff --git a/src/detection/tpm/tpm_windows.c b/src/detection/tpm/tpm_windows.c index a63a93f5f2..7a77eb3a78 100644 --- a/src/detection/tpm/tpm_windows.c +++ b/src/detection/tpm/tpm_windows.c @@ -3,10 +3,9 @@ // #include -#define TBS_SUCCESS 0u -#define TBS_E_INTERNAL_ERROR 0x80284001u -#define TBS_E_INVALID_CONTEXT 0x80284004u typedef UINT32 TBS_RESULT; +#define TBS_SUCCESS 0u +#define TBS_E_TPM_NOT_FOUND ((TBS_RESULT) 0x8028400Fu) #define TPM_VERSION_UNKNOWN 0 #define TPM_VERSION_12 1 @@ -42,7 +41,7 @@ const char* ffDetectTPM(FFTPMResult* result) TPM_DEVICE_INFO deviceInfo = {}; TBS_RESULT code = ffTbsi_GetDeviceInfo(sizeof(deviceInfo), &deviceInfo); if (code != TBS_SUCCESS) - return code == (TBS_RESULT) TBS_E_INVALID_CONTEXT ? "TPM device is not found" : "Tbsi_GetDeviceInfo() failed"; + return code == TBS_E_TPM_NOT_FOUND ? "TPM device is not found" : "Tbsi_GetDeviceInfo() failed"; switch (deviceInfo.tpmVersion) { diff --git a/src/detection/users/users_nosupport.c b/src/detection/users/users_nosupport.c new file mode 100644 index 0000000000..d7893ba463 --- /dev/null +++ b/src/detection/users/users_nosupport.c @@ -0,0 +1,7 @@ +#include "fastfetch.h" +#include "users.h" + +const char* ffDetectUsers(FFUsersOptions* options, FFlist* users) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/version/version.c b/src/detection/version/version.c index fe87e2e778..6e89c3b660 100644 --- a/src/detection/version/version.c +++ b/src/detection/version/version.c @@ -22,8 +22,9 @@ #define FF_ARCHITECTURE "unknown" #endif - -#if defined(__linux__) +#if defined(__ANDROID__) + #define FF_SYSNAME "Android" +#elif defined(__linux__) #define FF_SYSNAME "Linux" #elif defined(__FreeBSD__) #define FF_SYSNAME "FreeBSD" @@ -33,6 +34,8 @@ #define FF_SYSNAME "WIN32" #elif defined(__sun) #define FF_SYSNAME "SunOS" +#elif defined(__OpenBSD__) + #define FF_SYSNAME "OpenBSD" #else #define FF_SYSNAME "unknown" #endif diff --git a/src/detection/zpool/zpool.h b/src/detection/zpool/zpool.h index 8cd53da36a..aa8bee03eb 100644 --- a/src/detection/zpool/zpool.h +++ b/src/detection/zpool/zpool.h @@ -9,7 +9,7 @@ typedef struct FFZpoolResult uint64_t used; uint64_t total; uint64_t version; - uint64_t fragmentation; + double fragmentation; } FFZpoolResult; const char* ffDetectZpool(FFlist* result /* list of FFZpoolResult */); diff --git a/src/detection/zpool/zpool_linux.c b/src/detection/zpool/zpool_linux.c index 59890990b3..6c28def6db 100644 --- a/src/detection/zpool/zpool_linux.c +++ b/src/detection/zpool/zpool_linux.c @@ -73,7 +73,8 @@ static int enumZpoolCallback(zpool_handle_t* zpool, void* param) item->version = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_VERSION, &source); item->total = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_SIZE, &source); item->used = item->total - data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FREE, &source); - item->fragmentation = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FRAGMENTATION, &source); + uint64_t fragmentation = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FRAGMENTATION, &source); + item->fragmentation = fragmentation == UINT64_MAX ? 0.0/0.0 : (double) fragmentation; return 0; } diff --git a/src/logo/ascii/center.txt b/src/logo/ascii/center.txt index a4c365d0bb..58d64f79a7 100644 --- a/src/logo/ascii/center.txt +++ b/src/logo/ascii/center.txt @@ -1,13 +1,13 @@ - . - o, - . d, . - ';' ..d;.. .cl' - .:; 'oldO,.oo. - ..,:,xKXxoo;'. - ,;;;;;ldxkONMMMXxkxc;;;;;. - .....':oddXWMNOxlcl:...... - .:dlxk0c;:. . - :d:.,xcld,.,:. - ;l, .l; ';' - .o; - l, \ No newline at end of file + . + o, + . d, . + ';' ..d;.. .cl' + .:; 'oldO,.oo. + ..,:,xKXxoo;'. +,;;;;;ldxkONMMMXxkxc;;;;;. +.....':oddXWMNOxlcl:...... + .:dlxk0c;:. . + :d:.,xcld,.,:. + ;l, .l; ';' + .o; + l, \ No newline at end of file diff --git a/src/logo/ascii/cyberos.txt b/src/logo/ascii/cyberos.txt index c47301fd3a..0dea1b5331 100644 --- a/src/logo/ascii/cyberos.txt +++ b/src/logo/ascii/cyberos.txt @@ -1,15 +1,15 @@ -${c3} !M$EEEEEEEEEEEP - .MMMMM000000Nr. - ${c3}&MMMMMM${c2}MMMMMMMMMMMMM9 - ${c3}~MMM${c1}MMMM${c2}MMMMMMMMMMMMC - ${c1}" ${c3}M${c1}MMMMMMM${c2}MMMMMMMMMMs - ${c1}iM${c2}MMM&&${c1}MMMMMMMM${c2}MMMMMMMM\\ - ${c1}BMMM${c2}MMMMM${c1}MMMMMMM${c2}MMMMMM${c3}" - ${c1}9MMMMM${c2}MMMMMMM${c1}MMMM${c2}MMMM${c3}MMMf- - ${c2}sMMMMMMMM${c1}MM${c2}M${c3}MMMMMMMMM3_ - ${c2}+ffffffff${c1}P${c3}MMMMMMMMMMMM0 - ${c2}CMMMMMMMMMMM - }MMMMMMMMM - ~MMMMMMM - "RMMMM - .PMB \ No newline at end of file +${c3} !M$EEEEEEEEEEEP + .MMMMM000000Nr. + ${c3}&MMMMMM${c2}MMMMMMMMMMMMM9 + ${c3}~MMM${c1}MMMM${c2}MMMMMMMMMMMMC + ${c1}" ${c3}M${c1}MMMMMMM${c2}MMMMMMMMMMs + ${c1}iM${c2}MMM&&${c1}MMMMMMMM${c2}MMMMMMMM\\ + ${c1}BMMM${c2}MMMMM${c1}MMMMMMM${c2}MMMMMM${c3}" +${c1}9MMMMM${c2}MMMMMMM${c1}MMMM${c2}MMMM${c3}MMMf- + ${c2}sMMMMMMMM${c1}MM${c2}M${c3}MMMMMMMMM3_ + ${c2}+ffffffff${c1}P${c3}MMMMMMMMMMMM0 + ${c2}CMMMMMMMMMMM + }MMMMMMMMM + ~MMMMMMM + "RMMMM + .PMB \ No newline at end of file diff --git a/src/logo/ascii/eweos.txt b/src/logo/ascii/eweos.txt new file mode 100644 index 0000000000..0723acbc31 --- /dev/null +++ b/src/logo/ascii/eweos.txt @@ -0,0 +1,15 @@ +${c2} #####%%% +${c2} ##%%${c3}////${c2}%%%%%${c3}/// +${c2} #%%%%${c3}////((((////${c2}% +${c1} *@@@@@@@${c3}/${c5},,,${c3}/////${c5},,,${c2}%${c1}@@@@@@@ + .@@@@@@@@@@@${c3}////////${c2}%%%${c1}@@@@@@@@@@@@ +@@@${c4}...${c1}@@@@@@${c3}////${c2}%%${c3}////${c1}@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + @@@@@@@@@@@@@@@@@@@@@@@@@@@ + @@@@@@@@@@@@@@@@@@@@@@@ + @@@@@@ @@@@@@ + @@@ @@@ diff --git a/src/logo/ascii/midos.txt b/src/logo/ascii/midos.txt new file mode 100644 index 0000000000..4790708285 --- /dev/null +++ b/src/logo/ascii/midos.txt @@ -0,0 +1,20 @@ + .:=+*#%%@@@@@@%%#*+=:. + .=*%@@@@@@@@@@@@@@@@@@@@@@%*=: + .=%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%+. + :*@@@@@@@@@@@@@@@@@$2++$1%@@@@@@@@@@@@@@@@#- + .*@@@@@@@@@@@@@@@@@@%$2..$1#@@@@@@@@@@@@@@@@@@#. + -%@@@@@@@@@@@@@@@@@@@%$2..$1#@@@@@@@@@@@@@@@@@@@@- + -@@@@@@@@@@@@@@@@@@@@@%$2..$1#@@@@@@@@@@@@@@@@@@@@@= +:@@@@@@@@@@@@@@@@@%%@@@%$2..$1#@@@@#@@@@@@@@@@@@@@@@@: +*@@@@@@@@@@@@#$2*=:..$1*@@@%$2..$1#@@@#$2..:=+$1#@@@@@@@@@@@@* +%@@@@@@@#+$2=:...-+$1#@@@@@%$2..$1#@@@@@#$2+=:..:-$1+#@@@@@@@% +%@@@@@$2:..:=+-..-+$1#@@@@@%$2..$1#@@@@@%$2+-..-+=:..:$1@@@@@@ +*@@@@@$2*%$1@@@@@@%$2+-..$1#@@@%$2..$1#@@@%$2..-+$1#@@@@@@$2%*$1@@@@@* +:@@@@@@@@@@@@@@@@@$2#%$1@@@%$2..$1#@@@$2%#$1@@@@@@@@@@@@@@@@@: + =@@@@@@@@@@@@@@@@@@@@@%$2..$1#@@@@@@@@@@@@@@@@@@@@@= + -@@@@@@@@@@@@@@@@@@@@%$2..$1#@@@@@@@@@@@@@@@@@@@@= + .*@@@@@@@@@@@@@@@@@@%$2..$1#@@@@@@@@@@@@@@@@@@#: + :*@@@@@@@@@@@@@@@@@$2==$1%@@@@@@@@@@@@@@@@#-. + .+%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%+: + :=*%@@@@@@@@@@@@@@@@@@@@@@%*=:. + .-=+*#%%@@@@@@%%#*+=-. \ No newline at end of file diff --git a/src/logo/ascii/valhalla.txt b/src/logo/ascii/valhalla.txt new file mode 100644 index 0000000000..e9611793b0 --- /dev/null +++ b/src/logo/ascii/valhalla.txt @@ -0,0 +1,10 @@ + .:~: + !55P&#: + ^@G?G!&Y + !GYYGP55P: Y5J777!^:. +.GY?J#G!Y?5. ....P#7Y!##Y??57 +.5JY5PPY5GBBBPYYPBBGBYYP5PJP5: +^#J?Y@5?J5@@&!GG!&@@YJ?5@PJ7B? +5PY55G5YY5P!55YY5P7P5JJY5YYJ5Y +#G?J5@PJJP@~&55Y5@7@5JJG@5J?GB + .:.^:^^:!.!:!!:!:!:^^:^.:. \ No newline at end of file diff --git a/src/logo/ascii/xeroarch.txt b/src/logo/ascii/xeroarch.txt index 1f094ea061..890c2b2783 100644 --- a/src/logo/ascii/xeroarch.txt +++ b/src/logo/ascii/xeroarch.txt @@ -1,19 +1,19 @@ -${c1} ████ -${c1} ███${c2}▓▓${c1}███ -${c1} ███${c2}▓▓▓▓${c1}███ -${c1} ███${c2}▓▓▓▓▓▓${c1}███ -${c1} ███${c2}▓▓▓▓▓▓▓▓${c1}███ -${c1} ███${c2}▓▓▓▓▓▓▓▓▓▓${c1}███ -${c1} ███${c2}▓▓▓▓▓▓▓▓▓▓▓▓${c1}███ -${c1} ███${c2}▓▓▓▓▓▓${c1}██${c2}▓▓▓▓▓▓${c1}▓██ -${c1} ███${c2}▓▓▓▓▓▓${c1}████${c2}▓▓▓▓▓▓${c1}▓██ -${c1} ██▓${c2}▓▓▓▓▓▓${c1}█▓${c3}▓▓${c1}▓█${c2}▓▓▓▓▓▓${c1}▓██ -${c1} █████▓▒▒▒██${c3}▓${c4}▒▒${c3}▓${c1}██▒▒▒▓█████ -${c1} ███${c6}▓▓▓▓▓${c1}████${c3}▓${c4}▒▒▒▒${c3}▓${c1}▓███${c6}▓▓▓▓▓${c1}███ -${c1} ███${c6}▓▓▓▓▓▓▓▓▓${c1}███▓▓███${c6}▓▓▓▓▓▓▓▓▓${c1}███ -${c1} ███${c6}▓▓▓▓▓▓▓${c2}▓▓${c6}▓▓▓▓▓${c1}█${c6}▓▓▓▓▓▓▓▓▓▓▓▓▓${c1}███ -${c1} ███${c6}▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c6}▓▓▓${c1}▓${c6}▓▓▓▓${c4}()${c6}▓▓▓▓▓▓▓▓${c1}███ -${c1} ███${c6}▓▓▓▓▓${c2}▓▓${c5}▒▒▒▒▒▒${c6}${c2}▓▓${c6}▓${c1}▓${c6}▓▓${c3}()${c6}▓▓${c3}()${c6}▓▓▓▓▓▓▓${c1}███ -${c1}███${c6}▓▓▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c6}▓▓▓${c1}▓${c6}▓▓▓▓${c4}()${c6}▓▓▓▓▓▓▓▓▓▓${c1}███ -${c1}██${c6}▓▓▓▓▓▓▓▓▓▓▓${c2}▓▓${c6}▓▓▓▓▓${c1}▓${c6}▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓${c1}██ -${c1}████████████████████████████████████████ \ No newline at end of file +${c5} ████ +${c5} ███${c2}▓▓${c5}███ +${c5} ███${c2}▓▓▓▓${c5}███ +${c5} ███${c2}▓▓▓▓▓▓${c5}███ +${c5} ███${c2}▓▓▓▓▓▓▓▓${c5}███ +${c5} ███${c2}▓▓▓▓▓▓▓▓▓▓${c5}███ +${c5} ███${c2}▓▓▓▓▓▓▓▓▓▓▓▓${c5}███ +${c5} ███${c2}▓▓▓▓▓▓${c5}██${c2}▓▓▓▓▓▓${c5}▓██ +${c5} ███${c2}▓▓▓▓▓▓${c5}████${c2}▓▓▓▓▓▓${c5}▓██ +${c5} ██▓${c2}▓▓▓▓▓▓${c5}█▓${c3}▓▓${c5}▓█${c2}▓▓▓▓▓▓${c5}▓██ +${c5} █████▓▒▒▒██${c3}▓${c4}▒▒${c3}▓${c5}██▒▒▒▓█████ +${c5} ███${c6}▓▓▓▓▓${c5}████${c3}▓${c4}▒▒▒▒${c3}▓${c5}▓███${c6}▓▓▓▓▓${c5}███ +${c5} ███${c6}▓▓▓▓▓▓▓▓▓${c5}███▓▓███${c6}▓▓▓▓▓▓▓▓▓${c5}███ +${c5} ███${c6}▓▓▓▓▓▓▓${c2}▓▓${c6}▓▓▓▓▓${c5}█${c6}▓▓▓▓▓▓▓▓▓▓▓▓▓${c5}███ +${c5} ███${c6}▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c6}▓▓▓${c5}▓${c6}▓▓▓▓${c4}()${c6}▓▓▓▓▓▓▓▓${c5}███ +${c5} ███${c6}▓▓▓▓▓${c2}▓▓${c5}▒▒▒▒▒▒${c6}${c2}▓▓${c6}▓${c5}▓${c6}▓▓${c3}()${c6}▓▓${c3}()${c6}▓▓▓▓▓▓▓${c5}███ +${c5}███${c6}▓▓▓▓▓▓▓▓${c2}▓▓${c5}▒▒${c6}${c2}▓▓${c6}▓▓▓${c5}▓${c6}▓▓▓▓${c4}()${c6}▓▓▓▓▓▓▓▓▓▓${c5}███ +${c5}██${c6}▓▓▓▓▓▓▓▓▓▓▓${c2}▓▓${c6}▓▓▓▓▓${c5}▓${c6}▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓${c5}██ +${c5}████████████████████████████████████████ \ No newline at end of file diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 5235393d37..7ef6ce8fba 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -1498,6 +1498,18 @@ static const FFlogo E[] = { FF_COLOR_FG_WHITE, }, }, + // eweOS + { + .names = {"eweOS"}, + .lines = FASTFETCH_DATATEXT_LOGO_EWEOS, + .colors = { + FF_COLOR_FG_WHITE, + FF_COLOR_FG_LIGHT_YELLOW, + FF_COLOR_FG_LIGHT_RED, + FF_COLOR_FG_LIGHT_BLACK, + FF_COLOR_FG_RED, + }, + }, // Exherbo { .names = {"Exherbo", "exherbo-linux"}, @@ -2780,6 +2792,17 @@ static const FFlogo M[] = { .colorKeys = FF_COLOR_FG_BLUE, .colorTitle = FF_COLOR_FG_WHITE, }, + // MidOS + { + .names = {"MidOS"}, + .lines = FASTFETCH_DATATEXT_LOGO_MIDOS, + .colors = { + FF_COLOR_FG_LIGHT_BLACK, + FF_COLOR_FG_WHITE, + }, + .colorKeys = FF_COLOR_FG_LIGHT_BLACK, + .colorTitle = FF_COLOR_FG_WHITE, + }, // Mint { .names = {"mint", "mint-linux"}, @@ -3088,6 +3111,7 @@ static const FFlogo O[] = { FF_COLOR_FG_WHITE, FF_COLOR_FG_CYAN, FF_COLOR_FG_RED, + FF_COLOR_FG_LIGHT_BLACK, }, .colorKeys = FF_COLOR_FG_YELLOW, .colorTitle = FF_COLOR_FG_WHITE, @@ -4574,6 +4598,16 @@ static const FFlogo U[] = { }; static const FFlogo V[] = { + // Valhalla + { + .names = {"Valhalla", "valhallaos", "valhalla-linux"}, + .lines = FASTFETCH_DATATEXT_LOGO_VALHALLA, + .colors = { + FF_COLOR_FG_WHITE, + }, + .colorKeys = FF_COLOR_FG_WHITE, + .colorTitle = FF_COLOR_FG_WHITE, + }, // Vanilla { .names = {"vanilla", "vanilla-os", "vanilla-linux"}, @@ -4790,11 +4824,11 @@ static const FFlogo X[] = { .names = {"XeroArch"}, .lines = FASTFETCH_DATATEXT_LOGO_XEROARCH, .colors = { - FF_COLOR_FG_256 "16", + FF_COLOR_FG_256 "50", FF_COLOR_FG_256 "14", FF_COLOR_FG_256 "50", FF_COLOR_FG_256 "93", - FF_COLOR_FG_256 "46", + FF_COLOR_FG_256 "16", FF_COLOR_FG_256 "15", } }, diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 743c098e29..f27ff29e7f 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -7,7 +7,7 @@ #include "modules/battery/battery.h" #include "util/stringUtils.h" -#define FF_BATTERY_NUM_FORMAT_ARGS 10 +#define FF_BATTERY_NUM_FORMAT_ARGS 14 static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uint8_t index) { @@ -28,6 +28,17 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin })); } + + uint32_t timeRemaining = result->timeRemaining < 0 ? 0 : (uint32_t) result->timeRemaining; + + uint32_t seconds = timeRemaining % 60; + timeRemaining /= 60; + uint32_t minutes = timeRemaining % 60; + timeRemaining /= 60; + uint32_t hours = timeRemaining % 24; + timeRemaining /= 24; + uint32_t days = timeRemaining; + if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(key.chars, index, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY); @@ -52,6 +63,15 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin ffPercentAppendNum(&str, result->capacity, options->percent, str.length > 0, &options->moduleArgs); } + + if(result->timeRemaining > 0) + { + if(str.length > 0) + ffStrbufAppendS(&str, " ("); + + ffParseDuration(days, hours, minutes, seconds, &str); + ffStrbufAppendS(&str, " remaining)"); + } } if(showStatus) @@ -91,6 +111,10 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin FF_FORMAT_ARG(result->serial, "serial"), FF_FORMAT_ARG(result->manufactureDate, "manufacture-date"), FF_FORMAT_ARG(capacityBar, "capacity-bar"), + FF_FORMAT_ARG(days, "time-days"), + FF_FORMAT_ARG(hours, "time-hours"), + FF_FORMAT_ARG(minutes, "time-minutes"), + FF_FORMAT_ARG(seconds, "time-seconds"), })); } } @@ -226,6 +250,8 @@ void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_obj_add_strbuf(doc, obj, "serial", &battery->serial); yyjson_mut_obj_add_real(doc, obj, "temperature", battery->temperature); yyjson_mut_obj_add_uint(doc, obj, "cycleCount", battery->cycleCount); + if (battery->timeRemaining > 0) + yyjson_mut_obj_add_int(doc, obj, "timeRemaining", battery->timeRemaining); } FF_LIST_FOR_EACH(FFBatteryResult, battery, results) @@ -241,7 +267,7 @@ void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, void ffPrintBatteryHelpFormat(void) { - FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BATTERY_MODULE_NAME, "{4}, {5}", FF_BATTERY_NUM_FORMAT_ARGS, ((const char* []) { + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BATTERY_MODULE_NAME, "{4} ({12} hours {13} mins) [{5}]", FF_BATTERY_NUM_FORMAT_ARGS, ((const char* []) { "Battery manufacturer - manufacturer", "Battery model name - model-name", "Battery technology - technology", @@ -252,6 +278,10 @@ void ffPrintBatteryHelpFormat(void) "Battery serial number - serial", "Battery manufactor date - manufacture-date", "Battery capacity (percentage bar) - capacity-bar", + "Battery time remaining days - time-days", + "Battery time remaining hours - time-hours", + "Battery time remaining minutes - time-minutes", + "Battery time remaining seconds - time-seconds", })); } diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 53f39a467b..a1dcf78f09 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -6,7 +6,7 @@ #include -#define FF_DISPLAY_NUM_FORMAT_ARGS 18 +#define FF_DISPLAY_NUM_FORMAT_ARGS 19 static int sortByNameAsc(FFDisplayResult* a, FFDisplayResult* b) { @@ -181,6 +181,7 @@ void ffPrintDisplay(FFDisplayOptions* options) FF_FORMAT_ARG(result->manufactureYear, "manufacture-year"), FF_FORMAT_ARG(result->manufactureWeek, "manufacture-week"), FF_FORMAT_ARG(buf, "serial"), + FF_FORMAT_ARG(result->platformApi, "platform-api"), })); } } @@ -395,6 +396,8 @@ void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjs yyjson_mut_obj_add_uint(doc, obj, "serial", item->serial); else yyjson_mut_obj_add_null(doc, obj, "serial"); + + yyjson_mut_obj_add_str(doc, obj, "platformApi", item->platformApi); } } @@ -419,6 +422,7 @@ void ffPrintDisplayHelpFormat(void) "Year of manufacturing - manufacture-year", "Nth week of manufacturing in the year - manufacture-week", "Serial number - serial", + "The platform API used when detecting the display - platform-api", })); } diff --git a/src/modules/keyboard/keyboard.c b/src/modules/keyboard/keyboard.c new file mode 100644 index 0000000000..fcf5eba8bb --- /dev/null +++ b/src/modules/keyboard/keyboard.c @@ -0,0 +1,142 @@ +#include "common/percent.h" +#include "common/printing.h" +#include "common/jsonconfig.h" +#include "detection/keyboard/keyboard.h" +#include "modules/keyboard/keyboard.h" +#include "util/stringUtils.h" + +#define FF_KEYBOARD_NUM_FORMAT_ARGS 2 + +static void printDevice(FFKeyboardOptions* options, const FFKeyboardDevice* device, uint8_t index) +{ + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(FF_KEYBOARD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + ffStrbufPutTo(&device->name, stdout); + } + else + { + FF_PRINT_FORMAT_CHECKED(FF_KEYBOARD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_KEYBOARD_NUM_FORMAT_ARGS, ((FFformatarg[]) { + FF_FORMAT_ARG(device->name, "name"), + FF_FORMAT_ARG(device->serial, "serial"), + })); + } +} + +void ffPrintKeyboard(FFKeyboardOptions* options) +{ + FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFKeyboardDevice)); + + const char* error = ffDetectKeyboard(&result); + + if(error) + { + ffPrintError(FF_KEYBOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); + return; + } + + if(!result.length) + { + ffPrintError(FF_KEYBOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected"); + return; + } + + uint8_t index = 0; + FF_LIST_FOR_EACH(FFKeyboardDevice, device, result) + { + printDevice(options, device, result.length > 1 ? ++index : 0); + ffStrbufDestroy(&device->serial); + ffStrbufDestroy(&device->name); + } +} + +bool ffParseKeyboardCommandOptions(FFKeyboardOptions* options, const char* key, const char* value) +{ + const char* subKey = ffOptionTestPrefix(key, FF_KEYBOARD_MODULE_NAME); + if (!subKey) return false; + if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) + return true; + + return false; +} + +void ffParseKeyboardJsonObject(FFKeyboardOptions* options, yyjson_val* module) +{ + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(module, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + if(ffStrEqualsIgnCase(key, "type")) + continue; + + if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) + continue; + + ffPrintError(FF_KEYBOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key); + } +} + +void ffGenerateKeyboardJsonConfig(FFKeyboardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyKeyboardOptions))) FFKeyboardOptions defaultOptions; + ffInitKeyboardOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + +void ffGenerateKeyboardJsonResult(FF_MAYBE_UNUSED FFKeyboardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFKeyboardDevice)); + + const char* error = ffDetectKeyboard(&result); + + if(error) + { + yyjson_mut_obj_add_str(doc, module, "error", error); + return; + } + + yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result"); + FF_LIST_FOR_EACH(FFKeyboardDevice, device, result) + { + yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr); + yyjson_mut_obj_add_strbuf(doc, obj, "serial", &device->serial); + yyjson_mut_obj_add_strbuf(doc, obj, "name", &device->name); + } + + FF_LIST_FOR_EACH(FFKeyboardDevice, device, result) + { + ffStrbufDestroy(&device->serial); + ffStrbufDestroy(&device->name); + } +} + +void ffPrintKeyboardHelpFormat(void) +{ + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_KEYBOARD_MODULE_NAME, "{1} ({3})", FF_KEYBOARD_NUM_FORMAT_ARGS, ((const char* []) { + "Name - name", + "Serial number - serial", + })); +} + +void ffInitKeyboardOptions(FFKeyboardOptions* options) +{ + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_KEYBOARD_MODULE_NAME, + "List connected keyboards", + ffParseKeyboardCommandOptions, + ffParseKeyboardJsonObject, + ffPrintKeyboard, + ffGenerateKeyboardJsonResult, + ffPrintKeyboardHelpFormat, + ffGenerateKeyboardJsonConfig + ); + ffOptionInitModuleArg(&options->moduleArgs, ""); +} + +void ffDestroyKeyboardOptions(FFKeyboardOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/keyboard/keyboard.h b/src/modules/keyboard/keyboard.h new file mode 100644 index 0000000000..b54a3ccba9 --- /dev/null +++ b/src/modules/keyboard/keyboard.h @@ -0,0 +1,9 @@ +#pragma once + +#include "fastfetch.h" + +#define FF_KEYBOARD_MODULE_NAME "Keyboard" + +void ffPrintKeyboard(FFKeyboardOptions* options); +void ffInitKeyboardOptions(FFKeyboardOptions* options); +void ffDestroyKeyboardOptions(FFKeyboardOptions* options); diff --git a/src/modules/keyboard/option.h b/src/modules/keyboard/option.h new file mode 100644 index 0000000000..4f39eee19e --- /dev/null +++ b/src/modules/keyboard/option.h @@ -0,0 +1,11 @@ +#pragma once + +// This file will be included in "fastfetch.h", do NOT put unnecessary things here + +#include "common/option.h" + +typedef struct FFKeyboardOptions +{ + FFModuleBaseInfo moduleInfo; + FFModuleArgs moduleArgs; +} FFKeyboardOptions; diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index 0ca38374f7..a6bcd261ad 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -5,7 +5,7 @@ #include "util/stringUtils.h" #define FF_LOCALIP_DISPLAY_NAME "Local IP" -#define FF_LOCALIP_NUM_FORMAT_ARGS 7 +#define FF_LOCALIP_NUM_FORMAT_ARGS 8 #pragma GCC diagnostic ignored "-Wsign-conversion" static int sortIps(const FFLocalIpResult* left, const FFLocalIpResult* right) @@ -77,6 +77,12 @@ static void printIp(FFLocalIpResult* ip, bool markDefaultRoute) putchar(']'); flag = true; } + if (ip->flags.length) { + if (flag) fputs(" <", stdout); + ffStrbufWriteTo(&ip->flags, stdout); + putchar('>'); + flag = true; + } if (markDefaultRoute && flag && ip->defaultRoute) fputs(" *", stdout); } @@ -151,6 +157,7 @@ void ffPrintLocalIp(FFLocalIpOptions* options) FF_FORMAT_ARG(ip->defaultRoute, "is-default-route"), FF_FORMAT_ARG(ip->mtu, "mtu"), FF_FORMAT_ARG(speedStr, "speed"), + FF_FORMAT_ARG(ip->flags, "flags"), })); } ++index; @@ -163,6 +170,7 @@ void ffPrintLocalIp(FFLocalIpOptions* options) ffStrbufDestroy(&ip->ipv4); ffStrbufDestroy(&ip->ipv6); ffStrbufDestroy(&ip->mac); + ffStrbufDestroy(&ip->flags); } } @@ -236,6 +244,15 @@ bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, co return true; } + if (ffStrEqualsIgnCase(subKey, "show-flags")) + { + if (ffOptionParseBoolean(value)) + options->showType |= FF_LOCALIP_TYPE_FLAGS_BIT; + else + options->showType &= ~FF_LOCALIP_TYPE_FLAGS_BIT; + return true; + } + if(ffStrEqualsIgnCase(subKey, "compact")) { if (ffOptionParseBoolean(value)) @@ -348,6 +365,15 @@ void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "showFlags")) + { + if (yyjson_get_bool(val)) + options->showType |= FF_LOCALIP_TYPE_FLAGS_BIT; + else + options->showType &= ~FF_LOCALIP_TYPE_FLAGS_BIT; + continue; + } + if (ffStrEqualsIgnCase(key, "compact")) { if (yyjson_get_bool(val)) @@ -415,6 +441,9 @@ void ffGenerateLocalIpJsonConfig(FFLocalIpOptions* options, yyjson_mut_doc* doc, if (options->showType & FF_LOCALIP_TYPE_SPEED_BIT) yyjson_mut_obj_add_bool(doc, module, "showSpeed", true); + if (options->showType & FF_LOCALIP_TYPE_FLAGS_BIT) + yyjson_mut_obj_add_bool(doc, module, "showFlags", true); + if (options->showType & FF_LOCALIP_TYPE_COMPACT_BIT) yyjson_mut_obj_add_bool(doc, module, "compact", true); @@ -445,13 +474,20 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs FF_LIST_FOR_EACH(FFLocalIpResult, ip, results) { yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr); - yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", ip->defaultRoute); - yyjson_mut_obj_add_strbuf(doc, obj, "ipv4", &ip->ipv4); - yyjson_mut_obj_add_strbuf(doc, obj, "ipv6", &ip->ipv6); - yyjson_mut_obj_add_strbuf(doc, obj, "mac", &ip->mac); yyjson_mut_obj_add_strbuf(doc, obj, "name", &ip->name); - yyjson_mut_obj_add_int(doc, obj, "mtu", ip->mtu); - yyjson_mut_obj_add_int(doc, obj, "speed", ip->speed); + yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", ip->defaultRoute); + if (options->showType & FF_LOCALIP_TYPE_IPV4_BIT) + yyjson_mut_obj_add_strbuf(doc, obj, "ipv4", &ip->ipv4); + if (options->showType & FF_LOCALIP_TYPE_IPV6_BIT) + yyjson_mut_obj_add_strbuf(doc, obj, "ipv6", &ip->ipv6); + if (options->showType & FF_LOCALIP_TYPE_MAC_BIT) + yyjson_mut_obj_add_strbuf(doc, obj, "mac", &ip->mac); + if (options->showType & FF_LOCALIP_TYPE_MTU_BIT) + yyjson_mut_obj_add_int(doc, obj, "mtu", ip->mtu); + if (options->showType & FF_LOCALIP_TYPE_SPEED_BIT) + yyjson_mut_obj_add_int(doc, obj, "speed", ip->speed); + if (options->showType & FF_LOCALIP_TYPE_FLAGS_BIT) + yyjson_mut_obj_add_strbuf(doc, obj, "flags", &ip->flags); } FF_LIST_FOR_EACH(FFLocalIpResult, ip, results) @@ -460,6 +496,7 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs ffStrbufDestroy(&ip->ipv4); ffStrbufDestroy(&ip->ipv6); ffStrbufDestroy(&ip->mac); + ffStrbufDestroy(&ip->flags); } } @@ -473,6 +510,7 @@ void ffPrintLocalIpHelpFormat(void) "Is default route - is-default-route", "MTU size in bytes - mtu", "Link speed (formatted) - speed", + "Interface flags - flags", })); } @@ -492,7 +530,7 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options) ffOptionInitModuleArg(&options->moduleArgs, "󰩟"); options->showType = FF_LOCALIP_TYPE_IPV4_BIT | FF_LOCALIP_TYPE_PREFIX_LEN_BIT - #ifndef __ANDROID__ + #if !__ANDROID__ /*Permission denied*/ && !__OpenBSD__ /*Report invalid argument for some reason*/ | FF_LOCALIP_TYPE_DEFAULT_ROUTE_ONLY_BIT #endif ; diff --git a/src/modules/localip/option.h b/src/modules/localip/option.h index 1a01611528..511ec729db 100644 --- a/src/modules/localip/option.h +++ b/src/modules/localip/option.h @@ -14,6 +14,7 @@ typedef enum FFLocalIpType FF_LOCALIP_TYPE_PREFIX_LEN_BIT = 1 << 4, FF_LOCALIP_TYPE_MTU_BIT = 1 << 5, FF_LOCALIP_TYPE_SPEED_BIT = 1 << 6, + FF_LOCALIP_TYPE_FLAGS_BIT = 1 << 7, FF_LOCALIP_TYPE_COMPACT_BIT = 1 << 10, FF_LOCALIP_TYPE_DEFAULT_ROUTE_ONLY_BIT = 1 << 11, diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 1ce5ab8fd9..05f58a0e75 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -10,7 +10,7 @@ void ffPrintMemory(FFMemoryOptions* options) { - FFMemoryResult storage; + FFMemoryResult storage = {}; const char* error = ffDetectMemory(&storage); if(error) diff --git a/src/modules/modules.h b/src/modules/modules.h index 4f9fa7a407..e6594f0309 100644 --- a/src/modules/modules.h +++ b/src/modules/modules.h @@ -34,6 +34,7 @@ #include "modules/icons/icons.h" #include "modules/initsystem/initsystem.h" #include "modules/kernel/kernel.h" +#include "modules/keyboard/keyboard.h" #include "modules/lm/lm.h" #include "modules/loadavg/loadavg.h" #include "modules/locale/locale.h" @@ -41,6 +42,7 @@ #include "modules/media/media.h" #include "modules/memory/memory.h" #include "modules/monitor/monitor.h" +#include "modules/mouse/mouse.h" #include "modules/netio/netio.h" #include "modules/opengl/opengl.h" #include "modules/opencl/opencl.h" diff --git a/src/modules/monitor/monitor.c b/src/modules/monitor/monitor.c index 6fe9b91adf..701444c294 100644 --- a/src/modules/monitor/monitor.c +++ b/src/modules/monitor/monitor.c @@ -149,7 +149,7 @@ void ffInitMonitorOptions(FFMonitorOptions* options) ffOptionInitModuleBaseInfo( &options->moduleInfo, FF_MONITOR_MODULE_NAME, - "Alias of Display module; deprecated", + "Alias of Display module", ffParseMonitorCommandOptions, ffParseMonitorJsonObject, ffPrintMonitor, diff --git a/src/modules/mouse/mouse.c b/src/modules/mouse/mouse.c new file mode 100644 index 0000000000..27b749f47d --- /dev/null +++ b/src/modules/mouse/mouse.c @@ -0,0 +1,142 @@ +#include "common/percent.h" +#include "common/printing.h" +#include "common/jsonconfig.h" +#include "detection/mouse/mouse.h" +#include "modules/mouse/mouse.h" +#include "util/stringUtils.h" + +#define FF_MOUSE_NUM_FORMAT_ARGS 2 + +static void printDevice(FFMouseOptions* options, const FFMouseDevice* device, uint8_t index) +{ + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(FF_MOUSE_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + ffStrbufPutTo(&device->name, stdout); + } + else + { + FF_PRINT_FORMAT_CHECKED(FF_MOUSE_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_MOUSE_NUM_FORMAT_ARGS, ((FFformatarg[]) { + FF_FORMAT_ARG(device->name, "name"), + FF_FORMAT_ARG(device->serial, "serial"), + })); + } +} + +void ffPrintMouse(FFMouseOptions* options) +{ + FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFMouseDevice)); + + const char* error = ffDetectMouse(&result); + + if(error) + { + ffPrintError(FF_MOUSE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); + return; + } + + if(!result.length) + { + ffPrintError(FF_MOUSE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected"); + return; + } + + uint8_t index = 0; + FF_LIST_FOR_EACH(FFMouseDevice, device, result) + { + printDevice(options, device, result.length > 1 ? ++index : 0); + ffStrbufDestroy(&device->serial); + ffStrbufDestroy(&device->name); + } +} + +bool ffParseMouseCommandOptions(FFMouseOptions* options, const char* key, const char* value) +{ + const char* subKey = ffOptionTestPrefix(key, FF_MOUSE_MODULE_NAME); + if (!subKey) return false; + if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) + return true; + + return false; +} + +void ffParseMouseJsonObject(FFMouseOptions* options, yyjson_val* module) +{ + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(module, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + if(ffStrEqualsIgnCase(key, "type")) + continue; + + if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) + continue; + + ffPrintError(FF_MOUSE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key); + } +} + +void ffGenerateMouseJsonConfig(FFMouseOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyMouseOptions))) FFMouseOptions defaultOptions; + ffInitMouseOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + +void ffGenerateMouseJsonResult(FF_MAYBE_UNUSED FFMouseOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFMouseDevice)); + + const char* error = ffDetectMouse(&result); + + if(error) + { + yyjson_mut_obj_add_str(doc, module, "error", error); + return; + } + + yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result"); + FF_LIST_FOR_EACH(FFMouseDevice, device, result) + { + yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr); + yyjson_mut_obj_add_strbuf(doc, obj, "serial", &device->serial); + yyjson_mut_obj_add_strbuf(doc, obj, "name", &device->name); + } + + FF_LIST_FOR_EACH(FFMouseDevice, device, result) + { + ffStrbufDestroy(&device->serial); + ffStrbufDestroy(&device->name); + } +} + +void ffPrintMouseHelpFormat(void) +{ + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_MOUSE_MODULE_NAME, "{1} ({3})", FF_MOUSE_NUM_FORMAT_ARGS, ((const char* []) { + "Name - name", + "Serial number - serial", + })); +} + +void ffInitMouseOptions(FFMouseOptions* options) +{ + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_MOUSE_MODULE_NAME, + "List connected mouses", + ffParseMouseCommandOptions, + ffParseMouseJsonObject, + ffPrintMouse, + ffGenerateMouseJsonResult, + ffPrintMouseHelpFormat, + ffGenerateMouseJsonConfig + ); + ffOptionInitModuleArg(&options->moduleArgs, "󰍽"); +} + +void ffDestroyMouseOptions(FFMouseOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/mouse/mouse.h b/src/modules/mouse/mouse.h new file mode 100644 index 0000000000..d78a375ae0 --- /dev/null +++ b/src/modules/mouse/mouse.h @@ -0,0 +1,9 @@ +#pragma once + +#include "fastfetch.h" + +#define FF_MOUSE_MODULE_NAME "Mouse" + +void ffPrintMouse(FFMouseOptions* options); +void ffInitMouseOptions(FFMouseOptions* options); +void ffDestroyMouseOptions(FFMouseOptions* options); diff --git a/src/modules/mouse/option.h b/src/modules/mouse/option.h new file mode 100644 index 0000000000..db9ea18662 --- /dev/null +++ b/src/modules/mouse/option.h @@ -0,0 +1,11 @@ +#pragma once + +// This file will be included in "fastfetch.h", do NOT put unnecessary things here + +#include "common/option.h" + +typedef struct FFMouseOptions +{ + FFModuleBaseInfo moduleInfo; + FFModuleArgs moduleArgs; +} FFMouseOptions; diff --git a/src/modules/options.h b/src/modules/options.h index 783757d3a1..7cf98c1274 100644 --- a/src/modules/options.h +++ b/src/modules/options.h @@ -34,6 +34,7 @@ #include "modules/icons/option.h" #include "modules/initsystem/option.h" #include "modules/kernel/option.h" +#include "modules/keyboard/option.h" #include "modules/loadavg/option.h" #include "modules/locale/option.h" #include "modules/lm/option.h" @@ -41,6 +42,7 @@ #include "modules/media/option.h" #include "modules/memory/option.h" #include "modules/monitor/option.h" +#include "modules/mouse/option.h" #include "modules/netio/option.h" #include "modules/opengl/option.h" #include "modules/opencl/option.h" diff --git a/src/modules/os/os.c b/src/modules/os/os.c index c00676fced..8224b65c51 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -230,6 +230,8 @@ void ffInitOSOptions(FFOSOptions* options) "" #elif __sun "" + #elif __OpenBSD__ + "" #else "?" #endif diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 6666a9c6ee..210351631c 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -10,7 +10,7 @@ void ffPrintSwap(FFSwapOptions* options) { - FFSwapResult storage; + FFSwapResult storage = {}; const char* error = ffDetectSwap(&storage); if(error) diff --git a/src/modules/uptime/uptime.c b/src/modules/uptime/uptime.c index caccc1f86a..935957df11 100644 --- a/src/modules/uptime/uptime.c +++ b/src/modules/uptime/uptime.c @@ -34,47 +34,10 @@ void ffPrintUptime(FFUptimeOptions* options) if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_UPTIME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); + ffParseDuration(days, hours, minutes, seconds, &buffer); - if(days == 0 && hours == 0 && minutes == 0) - { - printf("%u seconds\n", seconds); - return; - } - - if(days > 0) - { - printf("%u day", days); - - if(days > 1) - putchar('s'); - - if(days >= 100) - fputs("(!)", stdout); - - if(hours > 0 || minutes > 0) - fputs(", ", stdout); - } - - if(hours > 0) - { - printf("%u hour", hours); - - if(hours > 1) - putchar('s'); - - if(minutes > 0) - fputs(", ", stdout); - } - - if(minutes > 0) - { - printf("%u min", minutes); - - if(minutes > 1) - putchar('s'); - } - - putchar('\n'); + ffStrbufPutTo(&buffer, stdout); } else { diff --git a/src/modules/zpool/zpool.c b/src/modules/zpool/zpool.c index 7288a03dd1..719d411bf3 100644 --- a/src/modules/zpool/zpool.c +++ b/src/modules/zpool/zpool.c @@ -34,7 +34,6 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i ffParseSize(result->total, &totalPretty); double bytesPercentage = result->total > 0 ? (double) result->used / (double) result->total * 100.0 : 0; - double fragPercentage = (double) result->fragmentation; if(options->moduleArgs.outputFormat.length == 0) { @@ -44,7 +43,7 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i ffStrbufSetF(&buffer, "%s / %s (", usedPretty.chars, totalPretty.chars); ffPercentAppendNum(&buffer, bytesPercentage, options->percent, false, &options->moduleArgs); ffStrbufAppendS(&buffer, ", "); - ffPercentAppendNum(&buffer, fragPercentage, options->percent, false, &options->moduleArgs); + ffPercentAppendNum(&buffer, result->fragmentation, options->percent, false, &options->moduleArgs); ffStrbufAppendF(&buffer, " frag) - %s", result->state.chars); ffStrbufPutTo(&buffer, stdout); } @@ -56,9 +55,9 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i ffPercentAppendBar(&bytesPercentageBar, bytesPercentage, options->percent, &options->moduleArgs); FF_STRBUF_AUTO_DESTROY fragPercentageNum = ffStrbufCreate(); - ffPercentAppendNum(&fragPercentageNum, fragPercentage, options->percent, false, &options->moduleArgs); + ffPercentAppendNum(&fragPercentageNum, result->fragmentation, options->percent, false, &options->moduleArgs); FF_STRBUF_AUTO_DESTROY fragPercentageBar = ffStrbufCreate(); - ffPercentAppendBar(&fragPercentageBar, fragPercentage, options->percent, &options->moduleArgs); + ffPercentAppendBar(&fragPercentageBar, result->fragmentation, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(buffer.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_ZPOOL_NUM_FORMAT_ARGS, ((FFformatarg[]) { FF_FORMAT_ARG(result->name, "name"), @@ -168,7 +167,7 @@ void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_m yyjson_mut_obj_add_uint(doc, obj, "used", zpool->used); yyjson_mut_obj_add_uint(doc, obj, "total", zpool->total); yyjson_mut_obj_add_uint(doc, obj, "version", zpool->version); - yyjson_mut_obj_add_uint(doc, obj, "fragmentation", zpool->fragmentation); + yyjson_mut_obj_add_real(doc, obj, "fragmentation", zpool->fragmentation); } FF_LIST_FOR_EACH(FFZpoolResult, zpool, results) diff --git a/src/options/general.c b/src/options/general.c index abb8d10546..a29c21960a 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -39,7 +39,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va else if (ffStrEqualsIgnCase(key, "detectVersion")) options->detectVersion = yyjson_get_bool(val); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) else if (ffStrEqualsIgnCase(key, "escapeBedrock")) options->escapeBedrock = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "playerName")) @@ -84,7 +84,7 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key else if(ffStrEqualsIgnCase(key, "--detect-version")) options->detectVersion = ffOptionParseBoolean(value); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) else if(ffStrEqualsIgnCase(key, "--escape-bedrock")) options->escapeBedrock = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--player-name")) diff --git a/src/options/general.h b/src/options/general.h index 8b14283d81..0a85df7672 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -16,7 +16,7 @@ typedef struct FFOptionsGeneral bool detectVersion; // Module options that cannot be put in module option structure - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) FFstrbuf playerName; bool escapeBedrock; FFDsForceDrmType dsForceDrm; diff --git a/src/options/modules.c b/src/options/modules.c index cea3c7af0d..755f65a87a 100644 --- a/src/options/modules.c +++ b/src/options/modules.c @@ -35,6 +35,7 @@ void ffOptionsInitModules(FFOptionsModules* options) ffInitIconsOptions(&options->icons); ffInitInitSystemOptions(&options->initSystem); ffInitKernelOptions(&options->kernel); + ffInitKeyboardOptions(&options->keyboard); ffInitLMOptions(&options->lm); ffInitLoadavgOptions(&options->loadavg); ffInitLocalIpOptions(&options->localIP); @@ -42,6 +43,7 @@ void ffOptionsInitModules(FFOptionsModules* options) ffInitMediaOptions(&options->media); ffInitMemoryOptions(&options->memory); ffInitMonitorOptions(&options->monitor); + ffInitMouseOptions(&options->mouse); ffInitNetIOOptions(&options->netIo); ffInitOSOptions(&options->os); ffInitOpenCLOptions(&options->openCL); @@ -110,6 +112,7 @@ void ffOptionsDestroyModules(FFOptionsModules* options) ffDestroyIconsOptions(&options->icons); ffDestroyInitSystemOptions(&options->initSystem); ffDestroyKernelOptions(&options->kernel); + ffDestroyKeyboardOptions(&options->keyboard); ffDestroyLMOptions(&options->lm); ffDestroyLoadavgOptions(&options->loadavg); ffDestroyLocalIpOptions(&options->localIP); @@ -117,6 +120,7 @@ void ffOptionsDestroyModules(FFOptionsModules* options) ffDestroyMediaOptions(&options->media); ffDestroyMemoryOptions(&options->memory); ffDestroyMonitorOptions(&options->monitor); + ffDestroyMouseOptions(&options->mouse); ffDestroyNetIOOptions(&options->netIo); ffDestroyOSOptions(&options->os); ffDestroyOpenCLOptions(&options->openCL); diff --git a/src/options/modules.h b/src/options/modules.h index 919d924089..4ff82f972f 100644 --- a/src/options/modules.h +++ b/src/options/modules.h @@ -36,6 +36,7 @@ typedef struct FFOptionsModules FFIconsOptions icons; FFInitSystemOptions initSystem; FFKernelOptions kernel; + FFKeyboardOptions keyboard; FFLMOptions lm; FFLoadavgOptions loadavg; FFLocalIpOptions localIP; @@ -43,6 +44,7 @@ typedef struct FFOptionsModules FFMediaOptions media; FFMemoryOptions memory; FFMonitorOptions monitor; + FFMouseOptions mouse; FFNetIOOptions netIo; FFOSOptions os; FFOpenCLOptions openCL; diff --git a/src/util/binary_linux.c b/src/util/binary_linux.c index e5c7f5c982..b9c521ca9c 100644 --- a/src/util/binary_linux.c +++ b/src/util/binary_linux.c @@ -1,6 +1,6 @@ #include "binary.h" -#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) +#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__) #include "common/io/io.h" #include "common/library.h" diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index b442eed54f..9eaeae38a5 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -12,7 +12,7 @@ #ifdef __APPLE__ #include #include -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__OpenBSD__) #include #endif @@ -34,7 +34,9 @@ static void getExePath(FFPlatform* platform) exePathLen = 0; else exePathLen--; // remove terminating NUL - #else + #elif defined(__OpenBSD__) + size_t exePathLen = 0; + #elif defined(__sun) ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1); exePath[exePathLen] = '\0'; #endif @@ -177,7 +179,7 @@ static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts) ffStrbufAppendS(&info->architecture, uts->machine); ffStrbufInit(&info->displayVersion); - #if defined(__FreeBSD__) || defined(__APPLE__) + #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) size_t length = sizeof(info->pageSize); sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &info->pageSize, &length, NULL, 0); #else diff --git a/src/util/platform/FFPlatform_windows.c b/src/util/platform/FFPlatform_windows.c index 961f88237a..c66b0ab105 100644 --- a/src/util/platform/FFPlatform_windows.c +++ b/src/util/platform/FFPlatform_windows.c @@ -1,5 +1,6 @@ #include "FFPlatform_private.h" #include "common/io/io.h" +#include "common/library.h" #include "util/stringUtils.h" #include "util/windows/unicode.h" #include "util/windows/registry.h" @@ -159,6 +160,17 @@ static void getUserShell(FFPlatform* platform) ffStrbufReplaceAllC(&platform->userShell, '\\', '/'); } +static void detectWine(FFstrbuf* buf) +{ + static const char *(__cdecl *pwine_get_version)(void); + HMODULE hntdll = GetModuleHandleW(L"ntdll.dll"); + if (!hntdll) return; + pwine_get_version = (void *)GetProcAddress(hntdll, "wine_get_version"); + if (!pwine_get_version) return; + ffStrbufAppendS(buf, buf->length ? " - wine " : "wine "); + ffStrbufAppendS(buf, pwine_get_version()); +} + static void getSystemReleaseAndVersion(FFPlatformSysinfo* info) { RTL_OSVERSIONINFOW osVersion = { .dwOSVersionInfoSize = sizeof(osVersion) }; @@ -187,6 +199,7 @@ static void getSystemReleaseAndVersion(FFPlatformSysinfo* info) else ffRegReadStrbuf(hKey, L"ReleaseId", &info->displayVersion, NULL); // For old Windows 10 } + detectWine(&info->displayVersion); ffRegReadStrbuf(hKey, L"BuildLabEx", &info->version, NULL);