MiniDevil As beautiful as a shell
welcome_utils.c File Reference

Welcome utilities. More...

#include "welcome_ui.h"
+ Include dependency graph for welcome_utils.c:

Detailed Description

Welcome utilities.

Definition in file welcome_utils.c.

Functions

void ft_msleep (int ms)
 Sleep for approximately ms millisecondes using a little trick. More...
 
void get_welcome_term_size (t_welcome_term *t)
 Get the terminal size and calculate centre coordinates. More...
 
void print_at_pos (int row, int col, const char *str)
 Move the terminal cursor to [row, col] and print str. More...
 
void print_centered (t_welcome_term *t, int row, const char *str, int len)
 Print string centered on the given row. More...
 

Function Documentation

◆ ft_msleep()

void ft_msleep ( int  ms)

Sleep for approximately ms millisecondes using a little trick.

  • Sets VMIN = 0 so read() doesn't wait for a character
  • Sets VTIME = ms / 100 so read() blocks for that many deciseconds before returning with nothing
  • The result is thus an imitation of a sleep that doesn't use usleep() which is not allowed by the Minishell subject
  • Original terminal settings are saved and restored after the read
Parameters
msMilliseconds to sleep
Warning
Because of VTIME resolution, precision is limited to ~100 ms

Definition at line 28 of file welcome_utils.c.

Referenced by animate_demon(), animate_loading(), animate_quote(), animate_title(), cleanup_screen(), draw_border_effect(), draw_welcome(), flash_demon_eyes(), print_quote_lines(), and ui_loop().

+ Here is the caller graph for this function:

◆ get_welcome_term_size()

void get_welcome_term_size ( t_welcome_term t)

Get the terminal size and calculate centre coordinates.

Falls back to 80x24 if ioctl fails

Parameters
tWelcome terminal structure to fill

Definition at line 52 of file welcome_utils.c.

References t_welcome_term::center_x, t_welcome_term::center_y, t_welcome_term::height, and t_welcome_term::width.

Referenced by draw_welcome().

+ Here is the caller graph for this function:

◆ print_at_pos()

void print_at_pos ( int  row,
int  col,
const char *  str 
)

Move the terminal cursor to [row, col] and print str.

Parameters
rowTarget row (starting at 1)
colTarget column (starting at 1)
strString to print at the given position

Definition at line 77 of file welcome_utils.c.

Referenced by animate_credits(), animate_loading(), animate_title(), cleanup_screen(), draw_border_effect(), flash_demon_eyes(), print_centered(), print_demon_line(), and print_quote_lines().

+ Here is the caller graph for this function:

◆ print_centered()

void print_centered ( t_welcome_term t,
int  row,
const char *  str,
int  len 
)

Print string centered on the given row.

Parameters
tTerminal dimensions
rowRow to print on
strString to print (ANSI supported)
lenVisible character count of str (used for centering)

Definition at line 90 of file welcome_utils.c.

References print_at_pos(), and t_welcome_term::width.

Referenced by animate_credits(), animate_loading(), animate_quote(), and print_quote_lines().

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

Go to the source code of this file.