Skip to content

Terminal clears for some reason #268

Open

Description

@aramrw

This video shows the problem

Screen.Recording.2025-07-14.205132.mp4

Activity

  1. certik commented on Jul 15, 2025

    @certik
    Collaborator

    I don't follow --- is the issue that the shell prints (null) sometimes? Can you post the program that does that?

  2. aramrw commented on Jul 15, 2025

    @aramrw
    Author

    no shell for some reason clears the terminal when it encounters null, neither nushell nor powershell do this

    that's why when there is no new line and the print ends with null it will clear the entire line, I showed this in the video as I compiled it and ran it with shell multiple times and there was no output

  3. certik commented on Jul 15, 2025

    @certik
    Collaborator

    I don't see any null being printed in the C code. Do you print \0 on the screen? Can you please post the code so that I can try it also?

    However when you remove \n I can see that the shell will not print the line, right? So that's a bug that we need to fix.

  4. aramrw commented on Jul 17, 2025

    @aramrw
    Author
    #include <stdbool.h>
    #include <stdio.h>
    #include <string.h>
    
    struct Cli {
      char *input;
    };
    
    // checks if the arg is a valid argument
    bool exists(char *arg) { return strcmp(arg, "--i"); }
    void match_arg(char *arg, struct Cli opts) {
      if (strcmp(arg, "--i") == 0) {
        opts.input = arg;
      }
    }
    void print_cli(struct Cli opts) { printf("%s", opts.input); }
    
    void parse_args(int argc, char *argv[], struct Cli opts) {
      for (int i = 1; i < argc; ++i) {
        char *arg = argv[i];
        match_arg(arg, opts);
      }
    }
    
    int main(int argc, char *argv[]) {
      printf("v0.0.1\n");
    
      struct Cli opts = {
          .input = NULL,
      };
    
      parse_args(argc, argv, opts);
      print_cli(opts);
    
      return 0;
    }

    null is bring printed by print_cli, input is NULL so it prints that.
    and yes, so when i remove \n the reason it clears the entire line is because NULL for some reason makes shell clear the terminal. Therefore the terminal prints v0.0.1(null), and when it encounters null it will clear that line

    thats why in the video you can see when \n is added to the version you can see the version, but NULL doesnt get printed like it should because it gets cleared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions