This commit is contained in:
ferreo 2024-11-30 18:56:00 +00:00
parent 24885847d5
commit 34b34540b9
35 changed files with 39828 additions and 97 deletions

5
debian/changelog vendored
View File

@ -1,5 +0,0 @@
upstream-name (1.0-101pika1) pika; urgency=medium
* Initial release. (Closes: #nnnn) <nnnn is the bug number of your ITP>
-- ferreo <harderthanfire@gmail.com> Wed, 18 Jan 2023 21:48:14 +0000

19
debian/control vendored
View File

@ -1,19 +0,0 @@
Source: upstream-name
Section: admin
Priority: optional
Maintainer: name <email>
Standards-Version: 4.6.1
Build-Depends: debhelper-compat (= 13)
Rules-Requires-Root: no
Package: pkgname1
Architecture: linux-any
# Delete any of these lines if un-used
Depends: ${misc:Depends}, depends
Recommends: high priority optdepends
Conflicts: conflicts
Suggests: low priority optdepends
Breaks: also conflicts!?
Provides: provides
#
Description: pkgdesc

67
debian/rules vendored
View File

@ -1,67 +0,0 @@
#! /usr/bin/make -f
## See debhelper(7) (uncomment to enable).
## Output every command that modifies files on the build system.
export DH_VERBOSE = 1
export PIKA_BUILD_ARCH = $(shell cat ../pika-build-arch)
## === the chain of command ===
## debuild runs a chain of dh functions in the following order:
## dh_testdir
## dh_clean
## dh_auto_clean
## dh_update_autotools_config
## dh_autoreconf
## dh_auto_configure
## dh_prep
## dh_build
## dh_auto_build
## dh_install
## dh_auto_install
## dh_installdocs
## dh_installchangelogs
## dh_perl
## dh_link
## dh_strip_nondeterminism
## dh_compress
## dh_fixperms
## dh_missing
## dh_dwz
## dh_strip
## dh_makeshlibs
## dh_shlibdeps
## dh_installdeb
## dh_gencontrol
## but you are most likely to only need to override the following:
## dh_clean
## dh_auto_configure
## dh_build
## dh_install
## === End end of region ===
## === overriding dh functions ===
## by default all dh functions will run a specific command based on the build system selected by "dh $@"
## if you have a makefile that does everything you need this is fine,
## but most likely you have no MakeFile and you want to add your own commands
## Note : overrides must be places above %:
## So here's a few examples:
## overriding dh_clean to make it not delete rust vendor files:
#override_dh_clean:
# echo "disabled"
## overriding dh_auto_configure to add custom configs:
#override_dh_auto_configure:
# $(srcdir)/configure -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_DATADIR=/usr/share -DCMAKE_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu -DBUILD_PLUGIN=OFF
## overriding dh_install to install files to a package:
#override_dh_auto_configure:
# mkdir -p debian/pikman/usr/bin
# cp pikman debian/pikman/usr/bin/
## === End end of region ===
## This here will start the build:
%:
dh $@

View File

@ -6,15 +6,12 @@ set -e
echo "$PIKA_BUILD_ARCH" > pika-build-arch echo "$PIKA_BUILD_ARCH" > pika-build-arch
VERSION="1.0" VERSION="0.1.0"
# Clone Upstream cd ./pikafetch/
mkdir -p ./src-pkg-name
cp -rvf ./debian ./src-pkg-name/
cd ./src-pkg-name/
# Get build deps # Get build deps
LOGNAME=root dh_make --createorig -y -l -p src-pkg-name_"$VERSION" || echo "dh-make: Ignoring Last Error" LOGNAME=root dh_make --createorig -y -l -p pikafetch_"$VERSION" || echo "dh-make: Ignoring Last Error"
apt-get build-dep ./ -y apt-get build-dep ./ -y
# Build package # Build package

View File

@ -0,0 +1,158 @@
0
46350 3495108348 1732992950017108896 7f7cb8ef643c5d4a9b9dfb38c13b99b8 0 /home/ferreo/.cache/zls/build_runner/21872970afd69e48a0847077e5196711/build_runner.zig
683 805530004 1732976893900812232 48fa2fa05be9e3e940ac3e629098502f 0 /home/ferreo/pika/pikafetch/pikafetch/build.zig
103 0 0 35b10ba982858800c98ffbaad5536a86 2 o/a32fcfc0e475f08356ed8aef4020640b/dependencies.zig
7616 2821391365 1703206115000000000 a112ef71b351e8f79f6f43c583ede25c 1 std/std.zig
23040 2821391362 1703206115000000000 da66963546b611ee7750a27396b7d1ea 1 std/start.zig
115223 2820809247 1703206115000000000 864599658ca312005d8d3860dcc5d44e 1 std/debug.zig
3149 4030717458 1732912747707814019 8f1f18990b1a8b2050d797088be9880b 0 /home/ferreo/.cache/zig/b/8f1f18990b1a8b2050d797088be9880b/builtin.zig
33165 2820809238 1703206115000000000 f94156764e93e22ac481419ae3dcd7e2 1 std/builtin.zig
87972 2820809226 1703206115000000000 2058e9176f2f8c413153da85bdefea9a 1 std/Target.zig
129328 3495051621 1703206115000000000 aa1c9ead6b093aa4fc744cbaf6cdb147 1 std/Target/x86.zig
73503 2820809266 1703206115000000000 4f495cdd87469544c122e37211fe3d16 1 std/math.zig
41362 2820809268 1703206115000000000 222d7cb14bd7ca087b75cbc16cba6dda 1 std/meta.zig
11091 2820809225 1703206115000000000 3b4e837c9f6b3b4fbb5b3b95148e553c 1 std/SemanticVersion.zig
61526 2820809250 1703206115000000000 00003d31510dec096134200d0d6ceecc 1 std/elf.zig
12325 2820809272 1703206115000000000 2229bf6824a9119504139fcdb850890e 1 std/os.zig
207296 1232426956 1703206115000000000 651fd04e37ca32286baf84da551c7ce0 1 std/os/linux.zig
12494 1232426952 1703206115000000000 e9933b000fa707703dab8f2fe68b002a 1 std/os/linux/tls.zig
293019 2820809275 1703206115000000000 3aef046ab18b515bbbbf65ba8531ef93 1 std/posix.zig
31762 2820809258 1703206115000000000 39822c5f2ad237650217b35e72989b75 1 std/heap.zig
12747 3985300612 1703206115000000000 0c84990d94912da71f88ccdd844ff032 1 std/heap/arena_allocator.zig
176912 2820809267 1703206115000000000 223e2fd0f89a74fd7d5132dbe48f1c2c 1 std/mem.zig
13626 897881987 1703206115000000000 98c52b2fa05c32ad77f1743a5f3383ee 1 std/mem/Allocator.zig
14239 2820809263 1703206115000000000 a69e9fd3810cdd1601c26dd47210af71 1 std/linked_list.zig
3917 3985300608 1703206115000000000 985cae2df1113f68d7f2eca79afe1887 1 std/heap/PageAllocator.zig
1301 3985300609 1703206115000000000 3db24c00baa9c03a40bfeaa152e28593 1 std/heap/ThreadSafeAllocator.zig
54097 2820809227 1703206115000000000 5fc2474d41197418fc547d7d64491a85 1 std/Thread.zig
10030 3657355105 1703206115000000000 6ec4900de2fa66c512d3a1a8b197182b 1 std/Thread/Mutex.zig
19056 2820809232 1703206115000000000 fbe5a337296572a6d62cbde681c465ea 1 std/atomic.zig
74835 2820809278 1703206115000000000 26bff32158c4e55ea1dbd7cbd193b2d5 1 std/process.zig
87217 2820809230 1703206115000000000 d82200bd8e9f05406e233eef46e48149 1 std/array_list.zig
95593 2820809221 1703206115000000000 eb7f21887b8d6d3a1ea72f4fb7e18f23 1 std/Build.zig
48541 3087019092 1703206115000000000 f0b7461b8459a4c71e300129f17dffb2 1 std/Build/Cache.zig
2248 3087019090 1703206115000000000 95a1bb668e0c39f345c83920bac861b7 1 std/Build/Cache/Directory.zig
35816 2820809254 1703206115000000000 9ad542fb9d5f647b2fd9aa956a4876f1 1 std/fs.zig
112808 3495051635 1703206115000000000 736eee48bb9f3802d7054c19abc437df 1 std/fs/Dir.zig
65843 3495051636 1703206115000000000 2f1e7806f11f80320d184c737b99b781 1 std/fs/File.zig
114248 2820809229 1703206115000000000 7aa5a3d5d7c75f7861328581549e6a5d 1 std/array_hash_map.zig
38005 2820809269 1703206115000000000 2df15a06c9368a128b68d617837153ef 1 std/multi_array_list.zig
12352 2820809246 1703206115000000000 85ba4034d104ed83a45a1bb6ea2f588a 1 std/crypto.zig
18622 1614807898 1703206115000000000 05742583e9b394547e0631c84131938c 1 std/crypto/siphash.zig
89980 2820809257 1703206115000000000 52e58e0e5a1dd700c7ba1de70432e45c 1 std/hash_map.zig
26882 3495051600 1703206115000000000 5b9ff543d20a09f8c07cb235a7f3c28e 1 std/Target/Query.zig
45679 2821391376 1703206115000000000 495dd771e7b568e386535b63332d9a02 1 std/zig.zig
52150 3495089553 1703206115000000000 d488bc81fd0ba877c413ee9c01ed7219 1 std/zig/system.zig
18992 3087019094 1703206115000000000 f8e31f1e40286aec688457f633c109d1 1 std/Build/Step.zig
27571 3087019093 1703206115000000000 f1a35ffb70613c5c506de0b9feb42a25 1 std/Build/Module.zig
16219 3222031973 1703206115000000000 ebb5646fc6c1cbeff8fff92f756e2694 1 std/Build/Step/WriteFile.zig
50900 2820809222 1703206115000000000 00b173ccd55aed075eef5aa1dccad55a 1 std/Progress.zig
29025 3495089538 1703206115000000000 2573e2c79bf66e3476b0024f0dfa2173 1 std/zig/ErrorBundle.zig
76968 3222031962 1703206115000000000 0500528ea762b29f66289290fec117d5 1 std/Build/Step/Compile.zig
112489 2820809248 1703206115000000000 d33cf67bbc2809a1c38591e04f1e3f51 1 std/dwarf.zig
31915 3222031963 1703206115000000000 6880c5430ee92854d2f87b8087aabbb0 1 std/Build/Step/ConfigHeader.zig
1884 568839109 1703206115000000000 4e39bcecc218a8cefd7304859e028778 1 std/math/log2.zig
5989 3657355106 1703206115000000000 9b884db4ae244ef2af3dcea90ca42736 1 std/Thread/Pool.zig
8321 2820809264 1703206115000000000 445ca968f1971dbcfae846f76f46cc2d 1 std/log.zig
106358 2820809253 1703206115000000000 9b602efb3cf67bc725c9853d5fe33864 1 std/fmt.zig
14616 2820809231 1703206115000000000 0fed3eb789529104667fd82e81a9af62 1 std/ascii.zig
13689 2821391370 1703206115000000000 131aba425aefaef0d374793c2dd9e731 1 std/time.zig
77139 3495051638 1703206115000000000 6ed68741d6922f90c45c6c388b6cdd8c 1 std/fs/path.zig
12563 1232426955 1703206115000000000 edca846565ef855c728e7372feed8676 1 std/os/linux/x86_64.zig
72708 2296319949 1703206115000000000 046fa60b44c156af61840e746b56a6c2 1 std/process/Child.zig
200963 1232426960 1703206115000000000 6382cd937e84a8fc6ae02341db586df9 1 std/os/windows.zig
394 3495108346 1732992950017108896 e2a5dc77f7477e12f9d09568c618e70c 0 /home/ferreo/.cache/zls/build_runner/21872970afd69e48a0847077e5196711/BuildConfig.zig
5954 2820809261 1703206115000000000 ca96a7daf60a978c600a94a94daaea90 1 std/json.zig
3257 166274477 1703206115000000000 b6a0926202bd08dbf296c65a9af6c72b 1 std/json/hashmap.zig
29391 166274483 1703206115000000000 8c1d345a91a2c23c70cadb25b14a213b 1 std/json/stringify.zig
25700 2820809260 1703206115000000000 2c3e57ebee88e5b426bac4e5144d55a2 1 std/io.zig
13386 1232426959 1703206115000000000 b23fdad07ce3b3bc638202a13d269a17 1 std/os/wasi.zig
6224 1614807900 1703206115000000000 1478fc3a3f5e7178b0ebc595cf60927a 1 std/crypto/tlcsprng.zig
2697 4163283260 1703206115000000000 8464fd0bdf5c1f8ba10a286a4fe46f4d 1 std/io/Writer.zig
29780 2821391361 1703206115000000000 f63bcad555043dc37b62da5b7656cb6e 1 std/sort.zig
51714 2419348248 1703206115000000000 eb8790d984ce4a6ddd6376d877c85ff1 1 std/sort/block.zig
82077 2821391373 1703206115000000000 d5fc31f78c3ec8b424ea391b2e65f728 1 std/unicode.zig
76391 3495051604 1703206115000000000 4668a311541b6be75afd88bf66028ad5 1 std/Target/arm.zig
17620 2821391364 1703206115000000000 11fc6dca32658eb05179945f9031219f 1 std/static_string_map.zig
10710 2419348249 1703206115000000000 f2973ab2be6115a15cf6c75a2be36ad3 1 std/sort/pdq.zig
7643 568839114 1703206115000000000 03910049e32f401cd3296cc1352aecb4 1 std/math/powi.zig
9239 3657355107 1703206115000000000 d703f6a7af8c150d259a587850decd1f 1 std/Thread/ResetEvent.zig
17590 2820809223 1703206115000000000 5ddd4d07802b9f332a306c207663eea0 1 std/Random.zig
3177 3495051595 1703206115000000000 ece4176296c0d5a4735a0e13195d3e89 1 std/Random/Xoshiro256.zig
23359 3657355103 1703206115000000000 55e7c53750c5f84af61f7e61406bc0f0 1 std/Thread/Condition.zig
1796 3657355110 1703206115000000000 43f2cf40b5fd32903bf18a54ea66fc91 1 std/Thread/WaitGroup.zig
5461 4163969357 1703206115000000000 ed6aac6dd443d6bdac1cf31688d1b444 1 std/io/tty.zig
14434 4163283259 1703206115000000000 2655b33c088dd930683d9eb843eaceb4 1 std/io/Reader.zig
55939 2820809251 1703206115000000000 9fbbf465379ce46a9365e411debc3ce1 1 std/enums.zig
1730 2820809256 1703206115000000000 36cb1b0b5e0bb7d10f9b200b0a751743 1 std/hash.zig
19972 3657355116 1703206115000000000 c36dede4b91e35db37ea45c66dbe6fe9 1 std/hash/crc.zig
3882 3770658462 1703206115000000000 168f6844905becfc3ec252416dbee69f 1 std/hash/crc/impl.zig
6449 4163969351 1703206115000000000 3bcfe7862cea857ee79939a098991ad5 1 std/io/fixed_buffer_stream.zig
2057 2820809241 1703206115000000000 a778ec13ef93e0ace847f52f066441fd 1 std/compress.zig
3736 4030712832 1703206115000000000 a5c9eee5eaf5943e22c8a03fac3f2841 1 std/compress/zlib.zig
23844 4163283257 1703206115000000000 61343f5304677e260ccaed8ba225c2b1 1 std/compress/flate/inflate.zig
7460 4163283253 1703206115000000000 1c1d1c1c4e61c64090b7ace80a4c2dab 1 std/compress/flate/container.zig
16625 4163283249 1703206115000000000 8ba4aa19f03596c0d0eb18045a7331e8 1 std/compress/flate/bit_reader.zig
7434 4163283245 1703206115000000000 a6347ffd91bdf7b166947d627e9f38c5 1 std/compress/flate/CircularBuffer.zig
3519 3657355112 1703206115000000000 4e3c7d701979e5945ab9f85fed59a579 1 std/hash/adler.zig
10966 4163283255 1703206115000000000 e24401bc06abbf873844211e243f0871 1 std/compress/flate/huffman_decoder.zig
1399 3087019101 1703206115000000000 40a7d4ac60d12c6e9ca294acaed35474 1 std/dwarf/FORM.zig
3900 3087019104 1703206115000000000 b5711d1b73e43c5aaea25647f88f9369 1 std/dwarf/TAG.zig
7395 3087019098 1703206115000000000 0736a520f4793791a2cfc257bfcfd3b6 1 std/dwarf/AT.zig
643 3087019100 1703206115000000000 6f6a9e4e1602df062ad02179710971c4 1 std/dwarf/EH.zig
94423 1232426949 1703206115000000000 936f06081ca66c21f2225e91832d8a41 1 std/os/linux/syscalls.zig
19768 3657355128 1703206115000000000 817d70e351edd4b746ab4c444c0d2b09 1 std/zig/system/x86.zig
1273 3495051603 1703206115000000000 92589c8e708010b66287cffb30b3644a 1 std/Target/arc.zig
69762 3495051605 1703206115000000000 d6af57434a87d01c08b32d2bfe25fdaa 1 std/Target/avr.zig
77144 3495051607 1703206115000000000 c690addfa0ddc66f16428c3843909a46 1 std/Target/csky.zig
16084 3495051608 1703206115000000000 ca6f1a2a9e6e8fa60a8331d7c5f5ce34 1 std/Target/hexagon.zig
7121 3495051610 1703206115000000000 d75880c23fe47c4e74168b752266aab9 1 std/Target/m68k.zig
2220 3495051612 1703206115000000000 d6af7e91115ce15de6cc6fa6b85ad607 1 std/Target/msp430.zig
81486 3495051602 1703206115000000000 c94083fc646f9b20640e65787e33fdc0 1 std/Target/amdgpu.zig
25913 3495051616 1703206115000000000 9d8c66f36c8cefa8cdeac8497ff9ed3d 1 std/Target/s390x.zig
1273 3495051622 1703206115000000000 1becbd14309ffd333ba9f93137feeab0 1 std/Target/xtensa.zig
1275 3495051619 1703206115000000000 3f87de4b4cab37706212bd9a456a8c58 1 std/Target/ve.zig
94346 3495051601 1703206115000000000 136876fa8ce544da55eab725094091a5 1 std/Target/aarch64.zig
2409 3495051606 1703206115000000000 1693b91547d868068f63e102f2ccb211 1 std/Target/bpf.zig
5236 3495051609 1703206115000000000 fd217450c001fea386e26e5ae8ee436e 1 std/Target/loongarch.zig
16066 3495051611 1703206115000000000 6e5fb373b9f2ae19c60dbed74eb241dc 1 std/Target/mips.zig
34534 3495051614 1703206115000000000 51352484986d855d36c4732d68bc73d0 1 std/Target/powerpc.zig
53948 3495051615 1703206115000000000 5dd87bdcf11a3787d33834ee1afcb1ea 1 std/Target/riscv.zig
19757 3495051617 1703206115000000000 81e62932de5b471d355190a547b0390a 1 std/Target/sparc.zig
77930 3495051618 1703206115000000000 0611f617b9ec2d1a8e22aa44c1fe7363 1 std/Target/spirv.zig
13279 3495051613 1703206115000000000 c4c3d3112933eb72020bc9eebc304ed2 1 std/Target/nvptx.zig
4508 3495051620 1703206115000000000 d86c84e4bae678df19d1bcef0e88aef9 1 std/Target/wasm.zig
19546 3087019105 1703206115000000000 eeb537ce254d8635c5876f3cb23ba2ab 1 std/dwarf/abi.zig
26403 3087019106 1703206115000000000 17cfec6893f0195cf3f2128e131aebbd 1 std/dwarf/call_frame.zig
71838 3087019107 1703206115000000000 472566d679006f02ce08a8e6d3ca5840 1 std/dwarf/expressions.zig
10091 2821391374 1703206115000000000 616a2d791eb8d67329f8198701e2bbad 1 std/valgrind.zig
23129 2821391360 1703206115000000000 b579436bcc763fc86642b2a1d69be89a 1 std/simd.zig
22737 3222031969 1703206115000000000 ed971823148663304bb616e576bc3ac1 1 std/Build/Step/Options.zig
17036 2820809249 1703206115000000000 e5e4bda8771008b986953e018b241bdd 1 std/dynamic_library.zig
17851 2820809262 1703206115000000000 62510503fe6b45659189d32c19c9dc45 1 std/leb128.zig
43084 3657355104 1703206115000000000 a67e9f409c649ae15d47dcc9582247f0 1 std/Thread/Futex.zig
1299 4163969345 1703206115000000000 9ea5eaf4f2d36e2273f3ecec7f813b61 1 std/io/buffered_writer.zig
9295 3222031965 1703206115000000000 268e240d3773b7543a10f2365b34cc53 1 std/Build/Step/InstallArtifact.zig
530 3495051593 1703206115000000000 6862d091fadcbbb652464ab10689bd23 1 std/Random/SplitMix64.zig
2496 2820809220 1703206115000000000 51fed0f372bbe1737cc4b59d4258ebe3 1 std/BitStack.zig
8372 3657355120 1703206115000000000 d48498b32f349820311bbf338ae1aae5 1 std/hash/wyhash.zig
1160 4163969349 1703206115000000000 32ae6866d358d400739c8281e2b92d26 1 std/io/counting_writer.zig
1618 4163283252 1703206115000000000 60e22c8a23680b34b51d27b486811807 1 std/compress/flate/consts.zig
13375 4163283248 1703206115000000000 239244362ca7a3d92e32a4518ccda927 1 std/compress/flate/Token.zig
36892 1614807896 1703206115000000000 aeaa6f15041af562aebdfbb8f2e94f9d 1 std/crypto/sha2.zig
20392 2820809252 1703206115000000000 a41115e4a4263ff02975e97d21f21847 1 std/fifo.zig
1464 3495089537 1703206115000000000 262bf5a41c36322233615e07256bc570 1 std/zig/Client.zig
8752 3495089542 1703206115000000000 2d7e0835ecf9b1ce89b625495c8209c2 1 std/zig/Server.zig
2591 3495051634 1703206115000000000 54cecc0501b004131b133c8ec52688b3 1 std/fs/AtomicFile.zig
23028 2820809233 1703206115000000000 5f649adf883cb2acad194b60017a4672 1 std/base64.zig
2685 3495051588 1703206115000000000 5244bfd5edd68ad074bfdf866029fa86 1 std/Random/ChaCha.zig
52267 1614807876 1703206115000000000 250bf69f713193c74da886706bb53369 1 std/crypto/chacha20.zig
5693 3087019103 1703206115000000000 01d731f8d28ba8382ff3c5885d5e0c75 1 std/dwarf/OP.zig
7399 1614807902 1703206115000000000 7e3716a3c82a36541c6cf09b56a96da0 1 std/crypto/utils.zig
1666 3495089550 1703206115000000000 87e0eb501395d68ddce525f8555f960c 1 std/zig/primitives.zig
64174 2820809239 1703206115000000000 ecfd926ec456ba7acf15b5e7bec5f532 1 std/c.zig
10812 3770658455 1703206115000000000 b5d2e09197008802157fd9bda951945e 1 std/c/linux.zig
65754 3495089555 1703206115000000000 38539b399943bc6b4a1cfc2662b13db6 1 std/zig/tokenizer.zig
14595 3657355113 1703206115000000000 9802848537ec3da81ac651945a298250 1 std/hash/auto_hash.zig
1539 4163969352 1703206115000000000 ca6d9ebe9107eb6ffe4cc4b92611772a 1 std/io/limited_reader.zig
3957 1232426953 1703206115000000000 8a6d08b36d5d25b29bdff67ade3e947b 1 std/os/linux/vdso.zig

View File

@ -0,0 +1,2 @@
pub const packages = struct {};
pub const root_deps: []const struct { []const u8, []const u8 } = &.{};

25
pikafetch/build.zig Normal file
View File

@ -0,0 +1,25 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const pci_ids_path = "data/pci.ids";
// Create the options module
const options = b.addOptions();
options.addOption([]const u8, "pci_ids_path", pci_ids_path);
const exe = b.addExecutable(.{
.name = "pikafetch",
.root_source_file = .{ .cwd_relative = "src/main.zig" },
.target = target,
.optimize = optimize,
});
// Add options to the executable
exe.root_module.addOptions("build_options", options);
exe.linkLibC();
b.installArtifact(exe);
}

72
pikafetch/build.zig.zon Normal file
View File

@ -0,0 +1,72 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "pikafetch",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.1.0",
// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.11.0",
// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding
// // `hash`, otherwise you are communicating that you expect to find the old hash at
// // the new URL.
// .url = "https://example.com/foo.tar.gz",
//
// // This is computed from the file contents of the directory of files that is
// // obtained after fetching `url` and applying the inclusion rules given by
// // `paths`.
// //
// // This field is the source of truth; packages do not come from a `url`; they
// // come from a `hash`. `url` is just one of many possible mirrors for how to
// // obtain a package matching this `hash`.
// //
// // Uses the [multihash](https://multiformats.io/multihash/) format.
// .hash = "...",
//
// // When this is provided, the package is found in a directory relative to the
// // build root. In this case the package's hash is irrelevant and therefore not
// // computed. This field and `url` are mutually exclusive.
// .path = "foo",
// // When this is set to `true`, a package is declared to be lazily
// // fetched. This makes the dependency only get fetched if it is
// // actually used.
// .lazy = false,
//},
},
// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package. Only files listed here will remain on disk
// when using the zig package manager. As a rule of thumb, one should list
// files required for compilation plus any license(s).
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
//"README.md",
},
}

View File

@ -0,0 +1,5 @@
pikafetch (0.1.0-101pika1) pika; urgency=medium
* Initial release.
-- ferreo <harderthanfire@gmail.com> Wed, 18 Jan 2023 21:48:14 +0000

13
pikafetch/debian/control Normal file
View File

@ -0,0 +1,13 @@
Source: pikafetch
Section: admin
Priority: optional
Maintainer: name <email>
Standards-Version: 4.6.1
Build-Depends: debhelper-compat (= 13), build-essentail, zig
Rules-Requires-Root: no
Package: pikafetch
Architecture: linux-any
Depends: ${misc:Depends}
Provides: pikafetch
Description: fetch written specifically for pikaOS

View File

@ -0,0 +1,24 @@
MIT License
Copyright (c) 2024 PikaOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Notes:
The contents of src/data/pci.ids is licensed under GNU General Public License (version 2 or higher)

17
pikafetch/debian/rules Executable file
View File

@ -0,0 +1,17 @@
#! /usr/bin/make -f
export DH_VERBOSE = 1
export PIKA_BUILD_ARCH = $(shell cat ../pika-build-arch)
%:
dh $@
override_dh_install:
dh_install
mkdir -p debian/pikafetch/usr/bin/
cp -vf pikafetch debian/pikafetch/usr/bin/
chmod 755 debian/pikafetch/usr/bin/pikafetch
chmod +x debian/pikafetch/usr/bin/pikafetch
override_dh_auto_build:
zig build-exe src/main.zig -O ReleaseFast -mcpu x86_64_v3 -lc --name pikafetch

View File

@ -0,0 +1,24 @@
const colors = @import("colors.zig");
pub fn getArt() []const []const u8 {
return &[_][]const u8{
colors.Color.yellow ++ colors.Color.bold ++ " - " ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " ---------------- " ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " ------------------ " ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " -------------------" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ "-- -----------=*-=----#####" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ "-----------------------------####--=######" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ "------------------------------++---+####" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ "=============----------------=+=-----" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ "=================-----------####+----" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ "==================----------*###=----" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ "===================-----------------" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " ==================-----------------" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " =================----------------" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " ===============------------::::" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " ============-:::::::::::::::" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " =======--:::::::::::::::" ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " .::::::::::::::::. " ++ colors.Color.reset,
colors.Color.yellow ++ colors.Color.bold ++ " ::::::: " ++ colors.Color.reset,
};
}

View File

@ -0,0 +1,7 @@
pub const Color = struct {
pub const yellow = "\x1b[33m";
pub const bold = "\x1b[1m";
pub const reset = "\x1b[0m";
pub const green = "\x1b[32m";
pub const red = "\x1b[31m";
};

38412
pikafetch/src/data/pci.ids Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
pub const margin_width = 4;
pub const gap_width = 4;
pub const max_art_length = 46;
pub const color_seq_len = "\x1b[33m\x1b[1m".len;

View File

@ -0,0 +1,106 @@
const std = @import("std");
const ascii_art = @import("../art/ascii_art.zig");
const layout = @import("layout.zig");
const terminal = @import("terminal.zig");
pub fn printDisplay(writer: anytype, info_lines: []const []const u8, term_size: terminal.TermSize) !void {
const art_lines = ascii_art.getArt();
var line_buf: [512]u8 = undefined;
var i: usize = 0;
while (i < @max(art_lines.len, info_lines.len)) : (i += 1) {
var pos: usize = 0;
@memset(line_buf[0..layout.margin_width], ' ');
pos += layout.margin_width;
if (i < art_lines.len) {
const art_line = art_lines[i];
@memcpy(line_buf[pos..][0..art_line.len], art_line);
pos += art_line.len;
const visible_len = if (std.mem.indexOf(u8, line_buf[0..pos], "\x1b[0m")) |reset_pos|
reset_pos - layout.color_seq_len
else
art_line.len;
if (visible_len < layout.max_art_length) {
const padding = layout.max_art_length - visible_len;
@memset(line_buf[pos..][0..padding], ' ');
pos += padding;
}
} else {
@memset(line_buf[pos..][0..layout.max_art_length], ' ');
pos += layout.max_art_length;
}
@memset(line_buf[pos..][0..layout.gap_width], ' ');
pos += layout.gap_width;
if (i < info_lines.len) {
const info_line = info_lines[i];
if (std.mem.startsWith(u8, info_line, "\x1b[") and std.mem.indexOf(u8, info_line, "███") != null) {
@memcpy(line_buf[pos..][0..info_line.len], info_line);
pos += info_line.len;
} else {
var visible_info_len: usize = 0;
var j: usize = 0;
var last_color_seq_start: ?usize = null;
var in_escape = false;
var last_safe_pos: usize = 0;
const available_width = if (term_size.cols > (layout.margin_width + layout.max_art_length + layout.gap_width))
term_size.cols - (layout.margin_width + layout.max_art_length + layout.gap_width)
else
0;
while (j < info_line.len) : (j += 1) {
if (info_line[j] == '\x1b') {
in_escape = true;
last_color_seq_start = j;
continue;
}
if (in_escape) {
if (info_line[j] == 'm') {
in_escape = false;
last_safe_pos = j + 1;
}
continue;
}
visible_info_len += 1;
if (!in_escape) {
last_safe_pos = j + 1;
}
if (visible_info_len > available_width) break;
}
if (j < info_line.len) {
@memcpy(line_buf[pos..][0..last_safe_pos], info_line[0..last_safe_pos]);
pos += last_safe_pos;
var needs_reset = false;
var k: usize = 0;
while (k < last_safe_pos) : (k += 1) {
if (info_line[k] == '\x1b') {
needs_reset = true;
}
}
if (needs_reset) {
@memcpy(line_buf[pos..][0..4], "\x1b[0m");
pos += 4;
}
} else {
@memcpy(line_buf[pos..][0..info_line.len], info_line);
pos += info_line.len;
}
}
}
line_buf[pos] = '\n';
pos += 1;
try writer.writeAll(line_buf[0..pos]);
}
}

View File

@ -0,0 +1,20 @@
const std = @import("std");
const os = std.os;
pub const TermSize = struct {
rows: u16,
cols: u16,
};
pub fn getTerminalSize() !TermSize {
var wsz: os.linux.winsize = undefined;
const fd = std.posix.STDOUT_FILENO;
const rc = os.linux.ioctl(fd, os.linux.T.IOCGWINSZ, @intFromPtr(&wsz));
if (rc == -1) {
return TermSize{ .rows = 24, .cols = 80 };
}
return TermSize{
.rows = wsz.ws_row,
.cols = wsz.ws_col,
};
}

27
pikafetch/src/main.zig Normal file
View File

@ -0,0 +1,27 @@
const std = @import("std");
const system_info = @import("system/info.zig");
const printer = @import("display/printer.zig");
const terminal = @import("display/terminal.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
const check = gpa.deinit();
if (check == .leak) std.debug.print("Memory leaked\n", .{});
}
const allocator = gpa.allocator();
const info = try system_info.SystemInfo.init(allocator);
defer info.deinit();
const term_size = try terminal.getTerminalSize();
const formatted_info = try info.formatInfo();
defer {
for (formatted_info) |line| {
info.allocator.free(line);
}
info.allocator.free(formatted_info);
}
try printer.printDisplay(std.io.getStdOut().writer(), formatted_info, term_size);
}

View File

@ -0,0 +1,97 @@
const std = @import("std");
const c = @cImport({
@cInclude("unistd.h");
});
pub const ShellInfo = struct {
name: []const u8,
};
pub fn getShellInfo(allocator: std.mem.Allocator) !ShellInfo {
if (std.process.getEnvVarOwned(allocator, "SHELL")) |shell_path| {
defer allocator.free(shell_path);
const shell_name = std.fs.path.basename(shell_path);
if (std.mem.endsWith(u8, shell_name, "login")) {
const base_shell = shell_name[0 .. shell_name.len - "login".len];
return ShellInfo{
.name = try allocator.dupe(u8, base_shell),
};
}
return ShellInfo{
.name = try allocator.dupe(u8, shell_name),
};
} else |_| {}
var current_pid = c.getppid();
var depth: u8 = 0;
const max_depth = 4;
while (depth < max_depth) : (depth += 1) {
const proc_path = try std.fmt.allocPrint(allocator, "/proc/{d}/comm", .{current_pid});
defer allocator.free(proc_path);
const proc_file = std.fs.openFileAbsolute(proc_path, .{}) catch |err| switch (err) {
error.FileNotFound => break,
else => return err,
};
defer proc_file.close();
var buffer: [256]u8 = undefined;
const bytes = try proc_file.readAll(&buffer);
const proc_name = std.mem.trim(u8, buffer[0..bytes], " \n\r\t");
const shell_names = [_][]const u8{
"bash", "zsh", "fish", "nu", "nushell", "sh", "ash", "dash",
"ksh", "tcsh", "csh", "ion", "elvish", "xonsh", "oil",
};
for (shell_names) |name| {
if (std.mem.eql(u8, proc_name, name)) {
return ShellInfo{
.name = try allocator.dupe(u8, proc_name),
};
}
}
const skip_names = [_][]const u8{
"sudo", "su", "strace", "gdb", "lldb", "login",
"ltrace", "perf", "time", "valgrind", "init", "nulogin",
};
var should_skip = false;
for (skip_names) |name| {
if (std.mem.eql(u8, proc_name, name)) {
should_skip = true;
break;
}
}
if (!should_skip) {
return ShellInfo{
.name = try allocator.dupe(u8, proc_name),
};
}
const stat_path = try std.fmt.allocPrint(allocator, "/proc/{d}/stat", .{current_pid});
defer allocator.free(stat_path);
const stat_file = std.fs.openFileAbsolute(stat_path, .{}) catch break;
defer stat_file.close();
var stat_buf: [1024]u8 = undefined;
const stat_bytes = try stat_file.readAll(&stat_buf);
const stat_content = stat_buf[0..stat_bytes];
var stat_iter = std.mem.tokenizeScalar(u8, stat_content, ' ');
_ = stat_iter.next();
_ = stat_iter.next();
_ = stat_iter.next();
const ppid_str = stat_iter.next() orelse break;
current_pid = try std.fmt.parseInt(c_int, ppid_str, 10);
}
return ShellInfo{
.name = try allocator.dupe(u8, "unknown"),
};
}

View File

@ -0,0 +1,53 @@
const std = @import("std");
const c = @cImport({
@cInclude("unistd.h");
});
pub fn getTerminal(allocator: std.mem.Allocator) ![]const u8 {
if (std.process.getEnvVarOwned(allocator, "TERM_PROGRAM")) |term| {
return term;
} else |_| {}
if (std.process.getEnvVarOwned(allocator, "KITTY_PID")) |pid| {
allocator.free(pid);
return allocator.dupe(u8, "kitty");
} else |_| {}
if (std.process.getEnvVarOwned(allocator, "WT_SESSION")) |session| {
allocator.free(session);
return allocator.dupe(u8, "Windows Terminal");
} else |_| {}
if (std.process.getEnvVarOwned(allocator, "ALACRITTY_SOCKET")) |socket| {
allocator.free(socket);
return allocator.dupe(u8, "Alacritty");
} else |_| {}
if (std.process.getEnvVarOwned(allocator, "KONSOLE_VERSION")) |version| {
allocator.free(version);
return allocator.dupe(u8, "Konsole");
} else |_| {}
if (std.process.getEnvVarOwned(allocator, "GNOME_TERMINAL_SCREEN")) |screen| {
allocator.free(screen);
return allocator.dupe(u8, "GNOME Terminal");
} else |_| {}
if (std.process.getEnvVarOwned(allocator, "LC_TERMINAL")) |term| {
return term;
} else |_| {}
if (std.process.getEnvVarOwned(allocator, "TERM")) |term| {
if (!std.mem.eql(u8, term, "linux")) {
return term;
}
allocator.free(term);
} else |_| {}
if (c.ttyname(c.STDIN_FILENO)) |tty_ptr| {
const tty = std.mem.span(tty_ptr);
return allocator.dupe(u8, tty);
}
return allocator.dupe(u8, "unknown");
}

View File

@ -0,0 +1,59 @@
const std = @import("std");
const Child = std.process.Child;
pub fn getWM(allocator: std.mem.Allocator) ![]const u8 {
const wayland_display = std.process.getEnvVarOwned(allocator, "WAYLAND_DISPLAY") catch null;
defer if (wayland_display) |wd| allocator.free(wd);
if (wayland_display != null) {
if (std.process.getEnvVarOwned(allocator, "XDG_CURRENT_DESKTOP")) |desktop| {
return desktop;
} else |_| {
if (std.process.getEnvVarOwned(allocator, "DESKTOP_SESSION")) |session| {
return session;
} else |_| {}
}
} else {
const display = std.process.getEnvVarOwned(allocator, "DISPLAY") catch null;
defer if (display) |d| allocator.free(d);
if (display != null) {
if (std.process.getEnvVarOwned(allocator, "XDG_CURRENT_DESKTOP")) |desktop| {
return desktop;
} else |_| {
if (std.process.getEnvVarOwned(allocator, "DESKTOP_SESSION")) |session| {
return session;
} else |_| {
if (std.process.getEnvVarOwned(allocator, "GDMSESSION")) |session| {
return session;
} else |_| {
if (std.process.getEnvVarOwned(allocator, "WINDOWMANAGER")) |wm| {
return wm;
} else |_| {}
}
}
}
var child = std.process.Child.init(&[_][]const u8{ "xprop", "-root", "_NET_WM_NAME" }, allocator);
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;
if (child.spawnAndWait()) |_| {
if (child.stdout) |stdout| {
var buffer: [1024]u8 = undefined;
const bytes = try stdout.reader().readAll(&buffer);
const output = std.mem.trim(u8, buffer[0..bytes], " \n\r\t");
if (std.mem.indexOf(u8, output, "=")) |pos| {
const wm_name = std.mem.trim(u8, output[pos + 1 ..], " \"");
if (wm_name.len > 0) {
return allocator.dupe(u8, wm_name);
}
}
}
} else |_| {}
}
}
return allocator.dupe(u8, "Unknown");
}

View File

@ -0,0 +1,19 @@
const std = @import("std");
pub fn getCPUInfo(allocator: std.mem.Allocator) ![]const u8 {
const file = try std.fs.openFileAbsolute("/proc/cpuinfo", .{});
defer file.close();
var buffer: [4096]u8 = undefined;
const bytes_read = try file.readAll(&buffer);
const content = buffer[0..bytes_read];
if (std.mem.indexOf(u8, content, "model name")) |pos| {
const line_end = std.mem.indexOf(u8, content[pos..], "\n") orelse content.len;
const colon = std.mem.indexOf(u8, content[pos..], ":") orelse return error.InvalidFormat;
const model = std.mem.trim(u8, content[pos + colon + 1 .. pos + line_end], " \t\r\n");
return allocator.dupe(u8, model);
}
return allocator.dupe(u8, "Unknown CPU");
}

View File

@ -0,0 +1,55 @@
const std = @import("std");
const os = std.os;
const c = @cImport({
@cInclude("sys/statvfs.h");
});
pub const DiskInfo = struct {
total: u64,
used: u64,
fs_type: []const u8,
allocator: std.mem.Allocator,
pub fn deinit(self: *const DiskInfo) void {
self.allocator.free(self.fs_type);
}
};
pub fn getDiskInfo(allocator: std.mem.Allocator, mount_point: []const u8) !DiskInfo {
var stats: c.struct_statvfs = undefined;
const rc = c.statvfs(mount_point.ptr, &stats);
if (rc != 0) return error.StatFailed;
const total = stats.f_blocks * stats.f_frsize;
const free = stats.f_bfree * stats.f_frsize;
const used = total - free;
// Get filesystem type
const mtab = try std.fs.openFileAbsolute("/proc/mounts", .{});
defer mtab.close();
var buffer: [4096]u8 = undefined;
const bytes = try mtab.readAll(&buffer);
const content = buffer[0..bytes];
var fs_type: []const u8 = "unknown";
var lines = std.mem.split(u8, content, "\n");
while (lines.next()) |line| {
var fields = std.mem.split(u8, line, " ");
_ = fields.next() orelse continue; // device
const mount = fields.next() orelse continue;
const fs = fields.next() orelse continue;
if (std.mem.eql(u8, mount, "/")) {
fs_type = try allocator.dupe(u8, fs);
break;
}
}
return DiskInfo{
.total = total,
.used = used,
.fs_type = fs_type,
.allocator = allocator,
};
}

View File

@ -0,0 +1,147 @@
const std = @import("std");
pub fn getGPUInfo(allocator: std.mem.Allocator) ![]const u8 {
const vendor_file = std.fs.openFileAbsolute("/sys/class/drm/card0/device/vendor", .{}) catch |err| switch (err) {
error.FileNotFound => return allocator.dupe(u8, "Unknown GPU"),
else => return err,
};
defer vendor_file.close();
const device_file = std.fs.openFileAbsolute("/sys/class/drm/card0/device/device", .{}) catch |err| switch (err) {
error.FileNotFound => return allocator.dupe(u8, "Unknown GPU"),
else => return err,
};
defer device_file.close();
var vendor_buf: [32]u8 = undefined;
var device_buf: [32]u8 = undefined;
const vendor_bytes = try vendor_file.readAll(&vendor_buf);
const device_bytes = try device_file.readAll(&device_buf);
const vendor_str = std.mem.trim(u8, vendor_buf[0..vendor_bytes], "\n\r \t0x");
const device_str = std.mem.trim(u8, device_buf[0..device_bytes], "\n\r \t0x");
const vendor_id = try std.fmt.parseInt(u32, vendor_str, 16);
const device_id = try std.fmt.parseInt(u32, device_str, 16);
const modalias_file = std.fs.openFileAbsolute("/sys/class/drm/card0/device/modalias", .{}) catch |err| switch (err) {
error.FileNotFound => null,
else => return err,
};
defer if (modalias_file) |f| f.close();
const name_file = std.fs.openFileAbsolute("/sys/class/drm/card0/device/product", .{}) catch |err| switch (err) {
error.FileNotFound => null,
else => return err,
};
defer if (name_file) |f| f.close();
const model_file = std.fs.openFileAbsolute("/sys/class/drm/card0/device/model", .{}) catch |err| switch (err) {
error.FileNotFound => null,
else => return err,
};
defer if (model_file) |f| f.close();
const subsystem_file = std.fs.openFileAbsolute("/sys/class/drm/card0/device/subsystem_device", .{}) catch |err| switch (err) {
error.FileNotFound => null,
else => return err,
};
defer if (subsystem_file) |f| f.close();
var name_buf: [256]u8 = undefined;
var gpu_name: []const u8 = "";
if (name_file) |f| {
const name_bytes = try f.readAll(&name_buf);
const name = std.mem.trim(u8, name_buf[0..name_bytes], "\n\r \t");
if (name.len > 0) {
gpu_name = name;
}
}
if (gpu_name.len == 0) {
if (model_file) |f| {
const name_bytes = try f.readAll(&name_buf);
const name = std.mem.trim(u8, name_buf[0..name_bytes], "\n\r \t");
if (name.len > 0) {
gpu_name = name;
}
}
}
if (findPCIName(vendor_id, device_id)) |model| {
return std.fmt.allocPrint(allocator, "{s} {s}", .{ switch (vendor_id) {
0x1002 => "AMD",
0x10de => "NVIDIA",
0x8086 => "Intel",
else => "Unknown",
}, model });
}
const driver_dir = std.fs.openDirAbsolute("/sys/class/drm/card0/device", .{}) catch |err| switch (err) {
error.FileNotFound => null,
else => return err,
};
if (driver_dir) |d| {
defer {
var dir = d;
dir.close();
}
var path_buf: [256]u8 = undefined;
const path = d.readLink("driver", &path_buf) catch |err| switch (err) {
error.FileNotFound => return std.fmt.allocPrint(allocator, "{s} GPU (0x{x:0>4})", .{ switch (vendor_id) {
0x1002 => "AMD",
0x10de => "NVIDIA",
0x8086 => "Intel",
else => "Unknown",
}, device_id }),
else => return err,
};
const driver = std.fs.path.basename(path);
return std.fmt.allocPrint(allocator, "{s} (0x{x:0>4}, {s})", .{ switch (vendor_id) {
0x1002 => "AMD",
0x10de => "NVIDIA",
0x8086 => "Intel",
else => "Unknown",
}, device_id, driver });
}
return std.fmt.allocPrint(allocator, "{s} GPU (0x{x:0>4})", .{ switch (vendor_id) {
0x1002 => "AMD",
0x10de => "NVIDIA",
0x8086 => "Intel",
else => "Unknown",
}, device_id });
}
const pci_ids = @embedFile("../../data/pci.ids");
fn findPCIName(vendor_id: u32, device_id: u32) ?[]const u8 {
var lines = std.mem.splitSequence(u8, pci_ids, "\n");
var current_vendor: ?u32 = null;
while (lines.next()) |line| {
if (line.len == 0 or line[0] == '#') continue;
if (line[0] != '\t') {
if (line.len < 4) continue;
const vid = std.fmt.parseInt(u32, line[0..4], 16) catch continue;
current_vendor = vid;
continue;
}
if (current_vendor) |vid| {
if (vid != vendor_id) continue;
if (line[0] == '\t' and line[1] != '\t') {
if (line.len < 5) continue;
const did = std.fmt.parseInt(u32, std.mem.trim(u8, line[1..5], " "), 16) catch continue;
if (did == device_id) {
return std.mem.trim(u8, line[6..], " \t");
}
}
}
}
return null;
}

View File

@ -0,0 +1,91 @@
const std = @import("std");
pub const SizeInfo = struct {
value: f64,
unit: []const u8,
};
pub const MemInfo = struct {
total: u64,
used: u64,
};
pub const SwapInfo = struct {
total: u64,
used: u64,
};
pub fn formatSize(bytes: u64) SizeInfo {
const units = [_][]const u8{ "B", "KiB", "MiB", "GiB", "TiB" };
var size: f64 = @floatFromInt(bytes);
var unit_index: usize = 0;
while (size >= 1024 and unit_index < units.len - 1) : (unit_index += 1) {
size /= 1024;
}
return SizeInfo{
.value = size,
.unit = units[unit_index],
};
}
pub fn getMemoryInfo() !MemInfo {
const file = try std.fs.openFileAbsolute("/proc/meminfo", .{});
defer file.close();
var buffer: [4096]u8 = undefined;
const bytes_read = try file.readAll(&buffer);
const content = buffer[0..bytes_read];
var total: u64 = 0;
var available: u64 = 0;
var found_count: u8 = 0;
var lines = std.mem.splitSequence(u8, content, "\n");
while (lines.next()) |line| {
if (std.mem.startsWith(u8, line, "MemTotal:")) {
total = try parseMemValue(line);
found_count += 1;
} else if (std.mem.startsWith(u8, line, "MemAvailable:")) {
available = try parseMemValue(line);
found_count += 1;
}
if (found_count == 2) break;
}
const used = total - available;
return MemInfo{ .total = total * 1024, .used = used * 1024 };
}
pub fn getSwapInfo() !SwapInfo {
const file = try std.fs.openFileAbsolute("/proc/meminfo", .{});
defer file.close();
var buffer: [4096]u8 = undefined;
const bytes_read = try file.readAll(&buffer);
const content = buffer[0..bytes_read];
var total: u64 = 0;
var free: u64 = 0;
var lines = std.mem.split(u8, content, "\n");
while (lines.next()) |line| {
if (std.mem.startsWith(u8, line, "SwapTotal:")) {
total = try parseMemValue(line);
} else if (std.mem.startsWith(u8, line, "SwapFree:")) {
free = try parseMemValue(line);
}
}
const used = total - free;
return SwapInfo{ .total = total * 1024, .used = used * 1024 };
}
fn parseMemValue(line: []const u8) !u64 {
var parts = std.mem.split(u8, line, ":");
_ = parts.next();
const value_str = parts.next() orelse return error.InvalidFormat;
const trimmed = std.mem.trim(u8, value_str, " kB\t\r\n");
return std.fmt.parseInt(u64, trimmed, 10);
}

View File

@ -0,0 +1,10 @@
const std = @import("std");
pub fn getMotherboard(allocator: std.mem.Allocator) ![]const u8 {
const product_name = try std.fs.openFileAbsolute("/sys/class/dmi/id/product_name", .{});
defer product_name.close();
var buffer: [256]u8 = undefined;
const size = try product_name.readAll(&buffer);
return allocator.dupe(u8, std.mem.trim(u8, buffer[0..size], "\n\r "));
}

View File

@ -0,0 +1,205 @@
const std = @import("std");
const colors = @import("../art/colors.zig");
const cpu = @import("hardware/cpu.zig");
const gpu = @import("hardware/gpu.zig");
const memory = @import("hardware/memory.zig");
const disk = @import("hardware/disk.zig");
const kernel = @import("os/kernel.zig");
const packages = @import("os/packages.zig");
const hostname = @import("os/hostname.zig");
const wm = @import("desktop/wm.zig");
const terminal = @import("desktop/terminal.zig");
const shell = @import("desktop/shell.zig");
const motherboard = @import("hardware/motherboard.zig");
pub const SystemInfo = struct {
username: []const u8,
hostname: []const u8,
os_name: []const u8,
kernel: []const u8,
uptime: u64,
memory_total: u64,
memory_used: u64,
allocator: std.mem.Allocator,
host: []const u8,
packages: u32,
wm: []const u8,
terminal: []const u8,
gpu: []const u8,
swap_total: u64,
swap_used: u64,
disk_total: u64,
disk_used: u64,
shell_name: []const u8,
cpu_info: []const u8,
pub fn init(allocator: std.mem.Allocator) !SystemInfo {
var username: ?[]const u8 = null;
var hostname_str: ?[]const u8 = null;
var os_name: ?[]const u8 = null;
var kernel_ver: ?[]const u8 = null;
var host: ?[]const u8 = null;
var wm_name: ?[]const u8 = null;
var terminal_name: ?[]const u8 = null;
var gpu_info: ?[]const u8 = null;
var shell_info: ?[]const u8 = null;
var cpu_info: ?[]const u8 = null;
errdefer {
if (username) |u| allocator.free(u);
if (hostname_str) |h| allocator.free(h);
if (os_name) |o| allocator.free(o);
if (kernel_ver) |k| allocator.free(k);
if (host) |h| allocator.free(h);
if (wm_name) |w| allocator.free(w);
if (terminal_name) |t| allocator.free(t);
if (gpu_info) |g| allocator.free(g);
if (shell_info) |s| allocator.free(s);
if (cpu_info) |c| allocator.free(c);
}
username = try hostname.getUsername(allocator);
hostname_str = try hostname.getHostname(allocator);
os_name = try hostname.getOSName(allocator);
kernel_ver = try kernel.getKernelVersion(allocator);
const mem_info = try memory.getMemoryInfo();
host = try motherboard.getMotherboard(allocator);
const pkg_count = try packages.getDpkgCount();
wm_name = try wm.getWM(allocator);
terminal_name = try terminal.getTerminal(allocator);
gpu_info = try gpu.getGPUInfo(allocator);
const shell_data = try shell.getShellInfo(allocator);
shell_info = shell_data.name;
cpu_info = try cpu.getCPUInfo(allocator);
const swap_info = try memory.getSwapInfo();
const disk_info = try disk.getDiskInfo(allocator, "/");
defer disk_info.deinit();
return SystemInfo{
.username = username.?,
.hostname = hostname_str.?,
.os_name = os_name.?,
.kernel = kernel_ver.?,
.uptime = 0, // TODO: Implement uptime
.memory_total = mem_info.total,
.memory_used = mem_info.used,
.allocator = allocator,
.host = host.?,
.packages = pkg_count,
.wm = wm_name.?,
.terminal = terminal_name.?,
.gpu = gpu_info.?,
.swap_total = swap_info.total,
.swap_used = swap_info.used,
.disk_total = disk_info.total,
.disk_used = disk_info.used,
.shell_name = shell_info.?,
.cpu_info = cpu_info.?,
};
}
pub fn deinit(self: *const SystemInfo) void {
self.allocator.free(self.username);
self.allocator.free(self.hostname);
self.allocator.free(self.os_name);
self.allocator.free(self.kernel);
self.allocator.free(self.host);
self.allocator.free(self.wm);
self.allocator.free(self.terminal);
self.allocator.free(self.gpu);
self.allocator.free(self.shell_name);
self.allocator.free(self.cpu_info);
}
pub fn formatInfo(self: *const SystemInfo) ![]const []const u8 {
var info = try std.ArrayList([]const u8).initCapacity(self.allocator, 14);
errdefer {
for (info.items) |item| {
self.allocator.free(item);
}
info.deinit();
}
const calculations = struct {
mem_percentage: u64,
swap_percentage: u64,
disk_percentage: u64,
mem_fmt: memory.SizeInfo,
mem_total_fmt: memory.SizeInfo,
swap_fmt: memory.SizeInfo,
swap_total_fmt: memory.SizeInfo,
disk_fmt: memory.SizeInfo,
disk_total_fmt: memory.SizeInfo,
usage_colors: [3][]const u8,
}{
.mem_percentage = @divFloor(self.memory_used * 100, self.memory_total),
.swap_percentage = if (self.swap_total > 0) @divFloor(self.swap_used * 100, self.swap_total) else 0,
.disk_percentage = if (self.disk_total > 0) @divFloor(self.disk_used * 100, self.disk_total) else 0,
.mem_fmt = memory.formatSize(self.memory_used),
.mem_total_fmt = memory.formatSize(self.memory_total),
.swap_fmt = memory.formatSize(self.swap_used),
.swap_total_fmt = memory.formatSize(self.swap_total),
.disk_fmt = memory.formatSize(self.disk_used),
.disk_total_fmt = memory.formatSize(self.disk_total),
.usage_colors = .{
getUsageColor(@divFloor(self.memory_used * 100, self.memory_total)),
getUsageColor(if (self.swap_total > 0) @divFloor(self.swap_used * 100, self.swap_total) else 0),
getUsageColor(if (self.disk_total > 0) @divFloor(self.disk_used * 100, self.disk_total) else 0),
},
};
try info.appendSlice(&[_][]const u8{
try std.fmt.allocPrint(self.allocator, "{s}{s}@{s}{s}", .{ colors.Color.yellow, self.username, self.hostname, colors.Color.reset }),
try std.fmt.allocPrint(self.allocator, "{s}------------{s}", .{ colors.Color.yellow, colors.Color.reset }),
try std.fmt.allocPrint(self.allocator, "{s}OS:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.os_name }),
try std.fmt.allocPrint(self.allocator, "{s}Host:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.host }),
try std.fmt.allocPrint(self.allocator, "{s}Kernel:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.kernel }),
try std.fmt.allocPrint(self.allocator, "{s}Packages:{s} {d} (dpkg)", .{ colors.Color.bold, colors.Color.reset, self.packages }),
try std.fmt.allocPrint(self.allocator, "{s}Shell:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.shell_name }),
try std.fmt.allocPrint(self.allocator, "{s}WM:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.wm }),
try std.fmt.allocPrint(self.allocator, "{s}Terminal:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.terminal }),
try std.fmt.allocPrint(self.allocator, "{s}CPU:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.cpu_info }),
try std.fmt.allocPrint(self.allocator, "{s}GPU:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.gpu }),
try std.fmt.allocPrint(self.allocator, "{s}Memory:{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s})", .{
colors.Color.bold, colors.Color.reset,
calculations.mem_fmt.value, calculations.mem_fmt.unit,
calculations.mem_total_fmt.value, calculations.mem_total_fmt.unit,
calculations.usage_colors[0], calculations.mem_percentage,
colors.Color.reset,
}),
try std.fmt.allocPrint(self.allocator, "{s}Swap:{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s})", .{
colors.Color.bold, colors.Color.reset,
calculations.swap_fmt.value, calculations.swap_fmt.unit,
calculations.swap_total_fmt.value, calculations.swap_total_fmt.unit,
calculations.usage_colors[1], calculations.swap_percentage,
colors.Color.reset,
}),
try std.fmt.allocPrint(self.allocator, "{s}Disk (/):{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s}) - xfs", .{
colors.Color.bold, colors.Color.reset,
calculations.disk_fmt.value, calculations.disk_fmt.unit,
calculations.disk_total_fmt.value, calculations.disk_total_fmt.unit,
calculations.usage_colors[2], calculations.disk_percentage,
colors.Color.reset,
}),
try std.fmt.allocPrint(self.allocator, "", .{}),
try std.fmt.allocPrint(self.allocator, "\x1b[30m███\x1b[31m███\x1b[32m███\x1b[33m███\x1b[34m███\x1b[35m███\x1b[36m███\x1b[37m███{s}", .{
colors.Color.reset,
}),
try std.fmt.allocPrint(self.allocator, "\x1b[90m███\x1b[91m███\x1b[92m███\x1b[93m███\x1b[94m███\x1b[95m███\x1b[96m███\x1b[97m███{s}", .{
colors.Color.reset,
}),
});
return info.toOwnedSlice();
}
};
fn getUsageColor(percentage: u64) []const u8 {
return if (percentage < 50)
colors.Color.green
else if (percentage < 75)
colors.Color.yellow
else
colors.Color.red;
}

View File

@ -0,0 +1,58 @@
const std = @import("std");
pub fn getHostname(allocator: std.mem.Allocator) ![]const u8 {
var hostname_buffer: [64]u8 = undefined;
const hostname = try std.posix.gethostname(&hostname_buffer);
return allocator.dupe(u8, hostname);
}
pub fn getUsername(allocator: std.mem.Allocator) ![]const u8 {
return std.process.getEnvVarOwned(allocator, "USER") catch
try allocator.dupe(u8, "unknown");
}
pub fn getOSName(allocator: std.mem.Allocator) ![]const u8 {
const os_release = std.fs.openFileAbsolute("/etc/os-release", .{}) catch |err| switch (err) {
error.FileNotFound => {
var uts: std.os.linux.utsname = undefined;
_ = std.os.linux.uname(&uts);
const len = std.mem.indexOfScalar(u8, &uts.sysname, 0) orelse uts.sysname.len;
return allocator.dupe(u8, uts.sysname[0..len]);
},
else => return err,
};
defer os_release.close();
var buffer: [4096]u8 = undefined;
const bytes_read = try os_release.readAll(&buffer);
const content = buffer[0..bytes_read];
var lines = std.mem.split(u8, content, "\n");
while (lines.next()) |line| {
if (std.mem.startsWith(u8, line, "PRETTY_NAME=")) {
const value = line["PRETTY_NAME=".len..];
const clean_value = if (value.len >= 2 and value[0] == '"' and value[value.len - 1] == '"')
value[1 .. value.len - 1]
else
value;
return allocator.dupe(u8, clean_value);
}
}
lines = std.mem.split(u8, content, "\n");
while (lines.next()) |line| {
if (std.mem.startsWith(u8, line, "NAME=")) {
const value = line["NAME=".len..];
const clean_value = if (value.len >= 2 and value[0] == '"' and value[value.len - 1] == '"')
value[1 .. value.len - 1]
else
value;
return allocator.dupe(u8, clean_value);
}
}
var uts: std.os.linux.utsname = undefined;
_ = std.os.linux.uname(&uts);
const len = std.mem.indexOfScalar(u8, &uts.sysname, 0) orelse uts.sysname.len;
return allocator.dupe(u8, uts.sysname[0..len]);
}

View File

@ -0,0 +1,9 @@
const std = @import("std");
pub fn getKernelVersion(allocator: std.mem.Allocator) ![]const u8 {
var uts: std.os.linux.utsname = undefined;
_ = std.os.linux.uname(&uts);
const len = std.mem.indexOfScalar(u8, &uts.release, 0) orelse uts.release.len;
return allocator.dupe(u8, uts.release[0..len]);
}

View File

@ -0,0 +1,106 @@
const std = @import("std");
const os = std.os;
pub fn getDpkgCount() !u32 {
@setEvalBranchQuota(20000);
const file = try std.fs.openFileAbsolute("/var/lib/dpkg/status", .{});
defer file.close();
const stat = try file.stat();
const mapped = try std.posix.mmap(
null,
@as(usize, @intCast(stat.size)),
std.posix.PROT.READ,
.{ .TYPE = std.os.linux.MAP_TYPE.PRIVATE },
file.handle,
0,
);
defer std.posix.munmap(mapped);
var count: u32 = 0;
var i: usize = 0;
const Vec = @Vector(32, u8);
const s_vec: Vec = @splat(@as(u8, 'S'));
const n_vec: Vec = @splat(@as(u8, '\n'));
const target = "Status: install ok installed";
const target_len = target.len;
while (i + 512 <= mapped.len) : (i += 512) {
inline for (0..16) |block| {
const offset = block * 32;
const data: Vec align(32) = @as(*align(1) const Vec, @ptrCast(&mapped[i + offset])).*;
const prev_data: Vec align(32) = if (i + offset > 0)
@as(*align(1) const Vec, @ptrCast(&mapped[i + offset - 1])).*
else
@splat(@as(u8, '\n'));
const matches = @select(bool, data == s_vec, prev_data == n_vec, data == s_vec);
const any_matches = @reduce(.Or, matches);
if (any_matches) {
inline for (0..32) |j| {
if (matches[j]) {
const pos = i + offset + j;
if (pos + target_len <= mapped.len) {
count +%= @intFromBool(isMatch(mapped[pos..], target));
}
}
}
}
}
}
const remaining = mapped.len - i;
if (remaining > target_len) {
while (i + target_len <= mapped.len) : (i += 1) {
const has_newline = i == 0 or mapped[i - 1] == '\n';
const is_s = mapped[i] == 'S';
count +%= @intFromBool(has_newline and is_s and isMatch(mapped[i..], target));
}
}
return count;
}
inline fn isMatch(str: []const u8, comptime pattern: []const u8) bool {
const Vec = @Vector(32, u8);
const first_chunk = pattern[0..@min(32, pattern.len)].*;
const pattern_vec: Vec = first_chunk ++ ([_]u8{0} ** (@as(u6, 32) - @min(@as(u6, 32), pattern.len)));
const data_vec: Vec align(32) = @as(*align(1) const Vec, @ptrCast(str)).*;
const diff = data_vec ^ pattern_vec;
const mask: Vec = @as(Vec, @splat(0)) | comptime blk: {
var m: [32]u8 = [_]u8{0} ** 32;
for (0..@min(32, pattern.len)) |i| m[i] = 0xFF;
break :blk m;
};
const masked_diff = diff & mask;
const any_diff = @reduce(.Or, masked_diff);
if (any_diff != 0) return false;
if (pattern.len > 32) {
const remaining = pattern[32..];
const rem_len = remaining.len;
var matches: u32 = 1;
var j: usize = 0;
while (j + 32 <= rem_len) : (j += 32) {
const rem_vec: Vec align(32) = @as(*align(1) const Vec, @ptrCast(str[32 + j ..])).*;
const pat_vec: Vec = remaining[j..][0..32].*;
matches &= @intFromBool(@reduce(.Or, rem_vec ^ pat_vec) == 0);
}
inline for (j..rem_len) |k| {
matches &= @intFromBool(str[32 + k] == remaining[k]);
}
return matches != 0;
}
return true;
}