Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tui: Fix TUI display issues in non-UTF-8 locales #1974

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GabrielKimm
Copy link

@GabrielKimm GabrielKimm commented Sep 29, 2024

This commit addresses the issue #1870 where the TUI displays incorrect characters in non-UTF-8 locales. The fix includes:

  • Checking the current locale
  • Using ASCII characters for graph display in non-UTF-8 locales
  • Adjusting character widths accordingly

Fixes: #1870

Signed-off-by: Gabriel Kim [email protected]

@GabrielKimm
Copy link
Author

GabrielKimm commented Sep 29, 2024

I've addressed the issue #1870 regarding the TUI display in non-UTF-8 locales. Here's a summary of the changes and their effects:

Before the fix:
image

In non-UTF-8 locales, the TUI was displaying incorrect characters, making the graph structure unclear and difficult to read.

After the fix:
image
image

Now, the TUI correctly detects the locale setting and adjusts its display accordingly. In non-UTF-8 locales, it uses ASCII characters to represent the graph structure, ensuring clarity and readability across different environments.

Key changes:

  1. Added locale detection to determine if UTF-8 is supported.
  2. Implemented alternative ASCII characters for graph representation in non-UTF-8 locales.
  3. Adjusted character width calculations to ensure proper alignment in both UTF-8 and non-UTF-8 environments.

These changes should resolve the display issues while maintaining the functionality and user experience of the TUI across various locale settings.

Please review and let me know if any further adjustments are needed.

cmds/tui.c Outdated Show resolved Hide resolved
cmds/tui.c Outdated Show resolved Hide resolved
cmds/tui.c Outdated Show resolved Hide resolved
Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, only some nitpicks below.

cmds/tui.c Outdated Show resolved Hide resolved
cmds/tui.c Outdated Show resolved Hide resolved
@honggyukim
Copy link
Collaborator

Hi @GabrielKimm, I see your name isn't correctly shown in the commit as follows.

commit 8340a73374fb17736ae81761d53acd6d351c5f5e (HEAD -> refs/heads/pull/1974)
Author:     0xGabriel <[email protected]>
AuthorDate: Mon Sep 30 01:51:49 2024 +0900

    Fix TUI display issues in non-UTF-8 locales
    
    This commit addresses the issue #1870 where the TUI displays
    incorrect characters in non-UTF-8 locales. The fix includes:
    
    - Checking the current locale
    - Using ASCII characters for graph display in non-UTF-8 locales
    - Adjusting character widths accordingly
    
    Fixes: #1870
    
    Signed-off-by: 0xGabriel <[email protected]>

Please put your real name rather than 0xGabriel.

You can check it at https://github.com/namhyung/uftrace/pull/1974.patch.

@GabrielKimm GabrielKimm force-pushed the fix-tui-non-utf8-locale branch 2 times, most recently from cc92917 to 39030ab Compare October 1, 2024 17:06
@honggyukim
Copy link
Collaborator

honggyukim commented Oct 1, 2024

Your author name isn't changed yet. Please update it together.

From 39030abbd0de2289fa0600f0395b006176ff4c52 Mon Sep 17 00:00:00 2001
From: 0xGabriel <[email protected]>

As far as I remember, your name is "Gabriel Kim" so please use your full name.

You can update it as follows.

$ git commit --amend --author "Gabriel Kim <[email protected]>" --no-edit -s

@honggyukim
Copy link
Collaborator

In addition, you need to put category prefix for the commit title as follows.

tui: Fix TUI display issues in non-UTF-8 locales

honggyukim added a commit to honggyukim/uftrace that referenced this pull request Oct 1, 2024
It usually takes some time to get patches for review but it'd be useful
to have a script for that.

The 'checkout-pr.sh' script accepts a single parameter to get the pull
request ID.
It fetches from the source repo and checkouts to the fetched head.

The example usage is as follows.

  $ ./misc/checkout-pr.sh 1974
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100 18502  100 18502    0     0  39899      0 --:--:-- --:--:-- --:--:-- 39875
  remote: Enumerating objects: 1, done.
  remote: Counting objects: 100% (1/1), done.
  remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)
  Unpacking objects: 100% (1/1), 354 bytes | 354.00 KiB/s, done.
  From https://github.com/GabrielKimm/uftrace
   * branch              fix-tui-non-utf8-locale -> FETCH_HEAD
  Switched to and reset branch 'pull/1974'

Now you're ready to review the pull request 1974 where can be found at
namhyung#1974.

Signed-off-by: Honggyu Kim <[email protected]>
@GabrielKimm GabrielKimm force-pushed the fix-tui-non-utf8-locale branch 3 times, most recently from deb66a3 to 6f8a9c8 Compare October 1, 2024 17:19
@GabrielKimm GabrielKimm changed the title Fix TUI display issues in non-UTF-8 locales tui : Fix TUI display issues in non-UTF-8 locales Oct 1, 2024
@GabrielKimm GabrielKimm changed the title tui : Fix TUI display issues in non-UTF-8 locales tui: Fix TUI display issues in non-UTF-8 locales Oct 1, 2024
honggyukim added a commit to honggyukim/uftrace that referenced this pull request Oct 1, 2024
It usually takes some time to get patches for review but it'd be useful
to have a script for that.

The 'checkout-pr.sh' script accepts a single parameter to get the pull
request ID.
It fetches from the source repo and checkouts to the fetched head.

The example usage is as follows.

  $ ./misc/checkout-pr.sh 1974
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100 18502  100 18502    0     0  39899      0 --:--:-- --:--:-- --:--:-- 39875
  remote: Enumerating objects: 1, done.
  remote: Counting objects: 100% (1/1), done.
  remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)
  Unpacking objects: 100% (1/1), 354 bytes | 354.00 KiB/s, done.
  From https://github.com/GabrielKimm/uftrace
   * branch              fix-tui-non-utf8-locale -> FETCH_HEAD
  Switched to and reset branch 'pull/1974'

Now you're ready to review the pull request 1974 where can be found at
namhyung#1974.

Signed-off-by: Honggyu Kim <[email protected]>
@honggyukim
Copy link
Collaborator

Please use your name "Gabriel Kim" rather than "GabrielKim".

This commit addresses the issue namhyung#1870 where the TUI displays
incorrect characters in non-UTF-8 locales. The fix includes:

- Checking the current locale
- Using ASCII characters for graph display in non-UTF-8 locales
- Adjusting character widths accordingly

Fixes: namhyung#1870

Signed-off-by: Gabriel Kim <[email protected]>
@honggyukim
Copy link
Collaborator

Thanks for the update. I will wait for @namhyung's review.

@GabrielKimm
Copy link
Author

Thanks for the update. I will wait for @namhyung's review.

Thank you so much for your invaluable feedback and guidance on this PR.
Your detailed comments and suggestions have been incredibly helpful in improving the quality of my contribution.

I truly appreciate the time and effort you've put into reviewing my work and providing such constructive advice.

Copy link
Collaborator

@honggyukim honggyukim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've just tested this and it looks fine but I have some concerns by checking the value of LANG.

The following can be another way to check if we can print graphical characters, but I'm not sure if it doesn't break other environments such as Android build, musl build, alpine Linux, etc.

#include <locale.h>
#include <wchar.h>

int can_print_utf8_graph_chars() {
    const char *graph_char = "★";
    wchar_t wc;

    setlocale(LC_CTYPE, "");

    int result = mbtowc(&wc, graph_char, MB_CUR_MAX);

    if (result > 0 && wc != L'\0')
        return true;

    return false;
}

cmds/tui.c Show resolved Hide resolved
namhyung pushed a commit that referenced this pull request Oct 4, 2024
It usually takes some time to get patches for review but it'd be useful
to have a script for that.

The 'checkout-pr.sh' script accepts a single parameter to get the pull
request ID.
It fetches from the source repo and checkouts to the fetched head.

The example usage is as follows.

  $ ./misc/checkout-pr.sh 1974
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100 18502  100 18502    0     0  39899      0 --:--:-- --:--:-- --:--:-- 39875
  remote: Enumerating objects: 1, done.
  remote: Counting objects: 100% (1/1), done.
  remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)
  Unpacking objects: 100% (1/1), 354 bytes | 354.00 KiB/s, done.
  From https://github.com/GabrielKimm/uftrace
   * branch              fix-tui-non-utf8-locale -> FETCH_HEAD
  Switched to and reset branch 'pull/1974'

Now you're ready to review the pull request 1974 where can be found at
#1974.

Signed-off-by: Honggyu Kim <[email protected]>
@namhyung
Copy link
Owner

namhyung commented Oct 6, 2024

It seems there are display issues still.

  1. The cursor line overflows to the next line
  2. alignment is broken with child functions - see set_program_name and strrchr.

uftrace-tui-non-utf8

@GabrielKimm
Copy link
Author

It seems there are display issues still.

  1. The cursor line overflows to the next line
  2. alignment is broken with child functions - see set_program_name and strrchr.

uftrace-tui-non-utf8

Thank you for your thorough review and for pointing out these remaining display issues. I appreciate your attention to detail.

  1. Cursor line overflow:
    I understand the problem with the cursor line overflowing to the next line. This is likely due to an miscalculation in handling the terminal width or character width, especially in non-UTF-8 locales. I will review the code for string length calculations and line wrapping logic to address this issue.

  2. Alignment of child functions:
    Thank you for bringing this to my attention. The misalignment of child functions, particularly for set_program_name and strrchr, is indeed a critical issue for readability. I will carefully examine the indentation logic and how it handles various function names, especially longer ones. I'll also double-check the character width calculations for different locales to ensure consistent alignment.

I plan to make the following improvements:

  • Implement more robust terminal width detection and output adjustment.
  • Refine the indentation and alignment logic, particularly for child function display.
  • Conduct thorough testing across various locale settings to ensure consistency.
  • Review and optimize the string length and display width calculation logic.

I'll update the PR with these changes soon 😊🙏🏻🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uftrace tui in docker shows ~T~\ ~T~@(1) instead of pseudographics
3 participants