From 597c7dcf1ca6dfec75374e3cd4f4f85a708b9fff Mon Sep 17 00:00:00 2001 From: Maieul BOYER Date: Sat, 20 Jul 2024 15:02:14 +0200 Subject: [PATCH] Remove manual detection of the column number, default to 80 if ioctl TCGETSIZE fails --- line/src/line_internals.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/line/src/line_internals.c b/line/src/line_internals.c index b7e80198..931c5ac6 100644 --- a/line/src/line_internals.c +++ b/line/src/line_internals.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/11 18:18:46 by maiboyer #+# #+# */ -/* Updated: 2024/07/11 18:20:08 by maiboyer ### ########.fr */ +/* Updated: 2024/07/20 15:01:37 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,11 +21,10 @@ /* ======================= Low level terminal handling ====================== */ -// FIXME: remove the sscanf here ! /* Use the ESC [6n escape sequence to query the horizontal cursor position * and return it. On error -1 is returned, on success the position of the * cursor. */ -t_error line_get_cursor_position(t_fd *input, t_fd *output, t_u32 *column_out) +/*t_error line_get_cursor_position(t_fd *input, t_fd *output, t_u32 *column_out) { char buf[32]; t_u32 i; @@ -50,17 +49,14 @@ t_error line_get_cursor_position(t_fd *input, t_fd *output, t_u32 *column_out) return (ERROR); return (*column_out = cols, NO_ERROR); } +*/ /* Try to get the number of columns in the current terminal, or assume 80 * if it fails. */ -t_u32 line_get_columns(t_fd *input, t_fd *output) -{ - struct winsize ws; - t_u32 cols; - t_u32 start; - - if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) - { +/* + // This was inside the if body + t_u32 cols; + t_u32 start; if (line_get_cursor_position(input, output, &start)) return (80); me_printf_fd(output, "\x1b[999C"); @@ -68,7 +64,14 @@ t_u32 line_get_columns(t_fd *input, t_fd *output) return (80); if (cols > start) me_printf_fd(output, "\x1b[%dD", cols - start); - return (cols); + */ +t_u32 line_get_columns(t_fd *input, t_fd *output) +{ + struct winsize ws; + + if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) + { + return (80); } else return (ws.ws_col);