LCOV - code coverage report
Current view: top level - src/tui - pane.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 42 42
Test Date: 2026-04-20 19:54:22 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /* SPDX-License-Identifier: GPL-3.0-or-later */
       2              : /* Copyright 2026 Peter Csaszar */
       3              : 
       4              : /**
       5              :  * @file tui/pane.c
       6              :  * @brief Pane geometry and layout implementation (US-11 v2).
       7              :  */
       8              : 
       9              : #include "tui/pane.h"
      10              : 
      11              : #include <string.h>
      12              : 
      13          261 : int pane_is_valid(const Pane *p) {
      14          261 :     return p && p->rows > 0 && p->cols > 0;
      15              : }
      16              : 
      17            2 : static void zero_layout(Layout *out) { memset(out, 0, sizeof(*out)); }
      18              : 
      19           34 : void layout_compute(Layout *out, int screen_rows, int screen_cols,
      20              :                     int left_width_hint) {
      21           34 :     if (!out) return;
      22           33 :     if (screen_rows < TUI_MIN_SCREEN_ROWS || screen_cols < TUI_MIN_SCREEN_COLS) {
      23            2 :         zero_layout(out);
      24            2 :         return;
      25              :     }
      26              : 
      27           31 :     int left = left_width_hint;
      28           31 :     if (left < TUI_MIN_LEFT_WIDTH) left = TUI_MIN_LEFT_WIDTH;
      29           31 :     if (left > TUI_MAX_LEFT_WIDTH) left = TUI_MAX_LEFT_WIDTH;
      30              : 
      31              :     /* History pane always needs at least 20 cols to be useful — shrink the
      32              :      * left pane if the terminal is too narrow to accommodate both. */
      33           31 :     int min_right = 20;
      34           31 :     if (screen_cols - left < min_right) {
      35            1 :         left = screen_cols - min_right;
      36            1 :         if (left < TUI_MIN_LEFT_WIDTH) left = TUI_MIN_LEFT_WIDTH;
      37              :     }
      38              : 
      39           31 :     int top_rows = screen_rows - 1; /* reserve last row for status line */
      40              : 
      41           31 :     out->dialogs.row  = 0;
      42           31 :     out->dialogs.col  = 0;
      43           31 :     out->dialogs.rows = top_rows;
      44           31 :     out->dialogs.cols = left;
      45              : 
      46           31 :     out->history.row  = 0;
      47           31 :     out->history.col  = left;
      48           31 :     out->history.rows = top_rows;
      49           31 :     out->history.cols = screen_cols - left;
      50              : 
      51           31 :     out->status.row   = screen_rows - 1;
      52           31 :     out->status.col   = 0;
      53           31 :     out->status.rows  = 1;
      54           31 :     out->status.cols  = screen_cols;
      55              : }
      56              : 
      57           82 : int pane_put_str(const Pane *p, Screen *s,
      58              :                   int row, int col, const char *utf8, uint8_t attrs) {
      59           82 :     if (!pane_is_valid(p) || !s || !utf8) return 0;
      60           81 :     if (row < 0 || row >= p->rows || col < 0 || col >= p->cols) return 0;
      61           77 :     int remaining = p->cols - col;
      62           77 :     return screen_put_str_n(s, p->row + row, p->col + col, remaining,
      63              :                             utf8, attrs);
      64              : }
      65              : 
      66           29 : void pane_fill(const Pane *p, Screen *s,
      67              :                int row, int col, int n, uint8_t attrs) {
      68           29 :     if (!pane_is_valid(p) || !s || n <= 0) return;
      69           28 :     if (row < 0 || row >= p->rows || col < 0 || col >= p->cols) return;
      70           28 :     if (col + n > p->cols) n = p->cols - col;
      71           28 :     screen_fill(s, p->row + row, p->col + col, n, attrs);
      72              : }
      73              : 
      74           42 : void pane_clear(const Pane *p, Screen *s) {
      75           42 :     if (!pane_is_valid(p) || !s) return;
      76          664 :     for (int r = 0; r < p->rows; r++) {
      77          623 :         screen_fill(s, p->row + r, p->col, p->cols, 0);
      78              :     }
      79              : }
        

Generated by: LCOV version 2.0-1