tiny-shell 0.2
A mini shell project aiming to gain knowledge about Win32 and Linux API
Loading...
Searching...
No Matches
io_wrap.h File Reference
#include <stdbool.h>
#include "../runner/res.h"
#include "cmd.h"
Include dependency graph for io_wrap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void io_set_last_status (enum run_result result)
 Set the result of last command (RUN_OK/RUN_FAIL/...)
 
void io_set_text_white ()
 Set default text color to white.
 
void io_set_prompt_visibility (bool visible)
 Config if prompt should be printed.
 
void scan_input (struct cmd *obj)
 Ask and convert user's input into command.
 
void format_success (char *fmt,...)
 Used format_xxx instead of printf and such for uniform output.
 
void format_output (char *fmt,...)
 Used format_xxx instead of printf and such for uniform output.
 
void format_usage (char *fmt,...)
 Used format_xxx instead of printf and such for uniform output.
 
void format_error (char *fmt,...)
 Used format_xxx instead of printf and such for uniform output.
 

Function Documentation

◆ format_error()

void format_error ( char * fmt,
... )

Used format_xxx instead of printf and such for uniform output.

Definition at line 89 of file io_wrap.c.

89 {
90 if(support_color())
91 printf(COLOR_RED);
92 printf("ERR: ");
93 va_list argptr; // NOLINT
94 va_start(argptr, fmt);
95 vfprintf(stdout, fmt, argptr);
96 va_end(argptr);
97 if(support_color())
98 printf(COLOR_DEFAULT);
99}
#define COLOR_DEFAULT
Definition io_wrap.c:18
#define COLOR_RED
Definition io_wrap.c:13
bool support_color()
Definition utils.c:58

References COLOR_DEFAULT, COLOR_RED, and support_color().

Referenced by add_path(), cmd_init_from_str(), main(), split_by_whitespaces(), and transform_quotes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_output()

void format_output ( char * fmt,
... )

Used format_xxx instead of printf and such for uniform output.

Definition at line 80 of file io_wrap.c.

80 {
81 if(support_color())
82 printf(COLOR_DEFAULT);
83 va_list argptr; // NOLINT
84 va_start(argptr, fmt);
85 vfprintf(stdout, fmt, argptr);
86 va_end(argptr);
87}

References COLOR_DEFAULT, and support_color().

Referenced by run_get_all_env(), run_get_env(), and run_help().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_success()

void format_success ( char * fmt,
... )

Used format_xxx instead of printf and such for uniform output.

Definition at line 69 of file io_wrap.c.

69 {
70 if(support_color())
71 printf(COLOR_GREEN);
72 va_list argptr; // NOLINT
73 va_start(argptr, fmt);
74 vfprintf(stdout, fmt, argptr);
75 va_end(argptr);
76 if(support_color())
77 printf(COLOR_DEFAULT);
78}
#define COLOR_GREEN
Definition io_wrap.c:11

References COLOR_DEFAULT, COLOR_GREEN, and support_color().

Referenced by add_path(), invoke_runner(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_usage()

void format_usage ( char * fmt,
... )

Used format_xxx instead of printf and such for uniform output.

Definition at line 57 of file io_wrap.c.

57 {
58 if(support_color())
59 printf(COLOR_YELLOW);
60 printf("USAGE: ");
61 va_list argptr; // NOLINT
62 va_start(argptr, fmt);
63 vfprintf(stdout, fmt, argptr);
64 va_end(argptr);
65 if(support_color())
66 printf(COLOR_DEFAULT);
67}
#define COLOR_YELLOW
Definition io_wrap.c:12

References COLOR_DEFAULT, COLOR_YELLOW, and support_color().

Referenced by cmd_init_from_str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_set_last_status()

void io_set_last_status ( enum run_result result)

Set the result of last command (RUN_OK/RUN_FAIL/...)

Definition at line 29 of file io_wrap.c.

29 {
30 *last_run_status() = result;
31}
enum run_result * last_run_status()
Definition io_wrap.c:24

References last_run_status().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_set_prompt_visibility()

void io_set_prompt_visibility ( bool visible)

Config if prompt should be printed.

Definition at line 42 of file io_wrap.c.

42 {
43 *is_prompt_visible() = visible;
44}
bool * is_prompt_visible()
Definition io_wrap.c:37

References is_prompt_visible().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_set_text_white()

void io_set_text_white ( )

Set default text color to white.

Definition at line 33 of file io_wrap.c.

33 {
34 *io_use_white_text() = true;
35}
static bool * io_use_white_text()
Definition io_wrap.c:19

References io_use_white_text().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scan_input()

void scan_input ( struct cmd * obj)

Ask and convert user's input into command.

Definition at line 47 of file io_wrap.c.

47 {
49 char buffer[INPUT_BUFFER_SIZE] = {0};
50 if(!fgets(buffer, INPUT_BUFFER_SIZE, stdin)) {
51 cmd_init_from_str(obj, "exit");
52 } else {
53 cmd_init_from_str(obj, buffer);
54 }
55}
void cmd_init_from_str(struct cmd *res, const char *str)
Build command from raw input.
Definition cmd.c:19
#define INPUT_BUFFER_SIZE
Definition config.h:5
void prompt_input()
Definition io_wrap.c:101

References cmd_init_from_str(), INPUT_BUFFER_SIZE, and prompt_input().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: