ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
display.c File Reference

Display width and centering utilities implementation. More...

Go to the source code of this file.

Functions

int display_width (const char *text)
 
int display_center_horizontal (const char *text, int terminal_width)
 
int display_center_vertical (int content_height, int terminal_height)
 

Detailed Description

Display width and centering utilities implementation.

Definition in file lib/util/display.c.

Function Documentation

◆ display_center_horizontal()

int display_center_horizontal ( const char *  text,
int  terminal_width 
)

Definition at line 32 of file lib/util/display.c.

32 {
33 if (!text || terminal_width <= 0) {
34 return 0;
35 }
36
37 int text_width = display_width(text);
38
39 // If text is empty or wider than terminal, don't add padding
40 if (text_width == 0 || text_width >= terminal_width) {
41 return 0;
42 }
43
44 // Calculate left padding to center
45 return (terminal_width - text_width) / 2;
46}
int display_width(const char *text)

References display_width().

Referenced by discovery_status_display().

◆ display_center_vertical()

int display_center_vertical ( int  content_height,
int  terminal_height 
)

Definition at line 48 of file lib/util/display.c.

48 {
49 if (content_height <= 0 || terminal_height <= 0) {
50 return 0;
51 }
52
53 if (content_height >= terminal_height) {
54 return 0;
55 }
56
57 return (terminal_height - content_height) / 2;
58}

Referenced by discovery_status_display().

◆ display_width()

int display_width ( const char *  text)

Definition at line 13 of file lib/util/display.c.

13 {
14 if (!text) {
15 return 0;
16 }
17
18 // Strip ANSI escape codes
19 char *stripped = ansi_strip_escapes(text, strlen(text));
20
21 // Use stripped version if available, otherwise use original text
22 const char *to_measure = stripped ? stripped : text;
23
24 // Calculate display width using UTF-8 aware calculation
25 int width = utf8_display_width(to_measure);
26 SAFE_FREE(stripped);
27
28 // Return 0 for empty or invalid input, otherwise return calculated width
29 return width < 0 ? 0 : width;
30}
char * ansi_strip_escapes(const char *input, size_t input_len)
Definition ansi.c:13
int utf8_display_width(const char *str)
Definition utf8.c:46

References ansi_strip_escapes(), and utf8_display_width().

Referenced by display_center_horizontal(), layout_print_two_column_row(), and terminal_screen_render().