Giter Site home page Giter Site logo

zig-termsize's Introduction

termsize

terminal size matters

CI License Info Release Zig Support

๐Ÿฌ features

Termsize is a zig library providing a multi-platform interface for resolving your terminal's current size in rows and columns. On most unix systems, this is similar invoking the stty(1) program, requesting the terminal size.

examples

const std = @import("std");
const termsize = @import("termsize");

pub fn main() !void {
    std.debug.print(
        "{any}",
        .{termsize.termSize(std.io.getStdOut())},
    );
}

๐Ÿ“ผ installing

Create a new exec project with zig init-exe. Copy the echo handler example above into src/main.zig

Create a build.zig.zon file to declare a dependency

.zon short for "zig object notation" files are essentially zig structs. build.zig.zon is zigs native package manager convention for where to declare dependencies

Starting in zig 0.12.0, you can use and should prefer

zig fetch --save https://github.com/softprops/zig-termsize/archive/refs/tags/v0.1.0.tar.gz

otherwise, to manually add it, do so as follows

.{
    .name = "my-app",
    .version = "0.1.0",
    .dependencies = .{
+        // ๐Ÿ‘‡ declare dep properties
+        .termsize = .{
+            // ๐Ÿ‘‡ uri to download
+            .url = "https://github.com/softprops/zig-termsize/archive/refs/tags/v0.1.0.tar.gz",
+            // ๐Ÿ‘‡ hash verification
+            .hash = "{current-hash}",
+        },
    },
}

the hash below may vary. you can also depend any tag with https://github.com/softprops/zig-termsize/archive/refs/tags/v{version}.tar.gz or current main with https://github.com/softprops/zig-termsize/archive/refs/heads/main/main.tar.gz. to resolve a hash omit it and let zig tell you the expected value.

Add the following in your build.zig file

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});

    const optimize = b.standardOptimizeOption(.{});
+    // ๐Ÿ‘‡ de-reference termsize dep from build.zig.zon
+    const termsize = b.dependency("termsize", .{
+        .target = target,
+        .optimize = optimize,
+    }).module("termsize");
    var exe = b.addExecutable(.{
        .name = "your-exe",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
+    // ๐Ÿ‘‡ add the termsize module to executable
+    exe.root_module.addImport("termsize", termsize);

    b.installArtifact(exe);
}

๐Ÿฅน for budding ziglings

Does this look interesting but you're new to zig and feel left out? No problem, zig is young so most us of our new are as well. Here are some resources to help get you up to speed on zig

- softprops 2024

zig-termsize's People

Contributors

softprops avatar nrdave avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.