Linux псевдографика в терминале

как вывести русские символы и символы псевдографики в консоль

Подскажите пожалуйста как в linux вывести русские символы и символы псевдографики в консоль. Символы псевдографики это линии углы и т. д. что бы таблицы, схемы, не сложные рисунки рисовать.

#include void main(void) < char i; for(i = -128; i < 127; i++) < printf("%c", i); >printf("\n"); > 
#include void main(void) < unsigned char i; for(i = 0; i < 255; i++) < printf("%c", i); >printf("\n"); > 
#include void main(void) < unsigned int i; for(i = 0; i < 65535; i++) < printf("%c", i); >printf("\n"); > 

Но во всех консолях в графических и в буквенных там где должны вывестись русские буквы или символы псевдографики выводятся вопросы или квадратики.

Команда locale вот что выдала:

LANG=ru_RU.UTF-8 LC_CTYPE="ru_RU.UTF-8" LC_NUMERIC="ru_RU.UTF-8" LC_TIME="ru_RU.UTF-8" LC_COLLATE="ru_RU.UTF-8" LC_MONETARY="ru_RU.UTF-8" LC_MESSAGES="ru_RU.UTF-8" LC_PAPER="ru_RU.UTF-8" LC_NAME="ru_RU.UTF-8" LC_ADDRESS="ru_RU.UTF-8" LC_TELEPHONE="ru_RU.UTF-8" LC_MEASUREMENT="ru_RU.UTF-8" LC_IDENTIFICATION="ru_RU.UTF-8" LC_ALL= 

Только пожалуйста не предлагайте библиотеки ncurses, libsvga и т.д.

Хотелось бы разобраться конкретно в возникшем вопросе. За помощь заранее благодарен.

Eddy_Em ☆☆☆☆☆ ( 22.07.12 17:32:24 MSK )
Последнее исправление: Eddy_Em 22.07.12 17:32:57 MSK (всего исправлений: 1)

Ты пытаешься вывести одним байтом символы, для которых в UTF-8 нужно два байта. И чему здесь удивляться?

2. Если тебе нужно что-то за пределами первой половины ascii, то юзай wchar либо glib’овые абстракции. Никогда не делай i < 255.

3. Прочитай debian i18n howto или классику, чтобы быть в курсе вещей.

И да, русский текст лучше не хардкодить, а делать через gettext.

#include #include int main() < setlocale(LC_ALL, ""); // C++ std::wcout "); printf(""); wprintf(L"«раз %S\n", L"два»"); return 0; > 

А по алфавиту их вывести? Например, так:

cat 1.c #include main() < int i; char alephbeth[] = "абвгдежзиклмнопрстуфхцчшщьыъэюя"; for(i = 1; i < sizeof(alephbeth); i++) printf("%2d-я буква алфавита: %c\n", i, alephbeth[i-1]); >gcc 1.c && ./a.out 1-я буква алфавита: а 2-я буква алфавита: б 3-я буква алфавита: в 4-я буква алфавита: г 5-я буква алфавита: д 6-я буква алфавита: е 7-я буква алфавита: ж 8-я буква алфавита: з 9-я буква алфавита: и 10-я буква алфавита: к 11-я буква алфавита: л 12-я буква алфавита: м 13-я буква алфавита: н 14-я буква алфавита: о 15-я буква алфавита: п 16-я буква алфавита: р 17-я буква алфавита: с 18-я буква алфавита: т 19-я буква алфавита: у 20-я буква алфавита: ф 21-я буква алфавита: х 22-я буква алфавита: ц 23-я буква алфавита: ч 24-я буква алфавита: ш 25-я буква алфавита: щ 26-я буква алфавита: ь 27-я буква алфавита: ы 28-я буква алфавита: ъ 29-я буква алфавита: э 30-я буква алфавита: ю 31-я буква алфавита: я 

Главное, чтобы он исходник сохранил в UTF-8

Читайте также:  Linux stop stopped jobs

Ни в коем случае не char. Примерно так, но wchar_t, sizeof(alphbeth)/size(wchar_t), и %C. И не забыть setlocale

у него koi-8r головного мозга

Источник

10 Tools to Generate and Have Fun With ASCII Art in Linux Terminal

Think Linux terminal is all about serious work? Think again. Here are a few fun things you can do with ASCII art in the terminal.

ascii art tools linux

Linux terminal is not as scary as you think. Of course, it could be intimidating in the beginning but once you know the terminal better, you start loving it. You are likely to use the terminal for serious work. But there are many fun stuff you can do in the terminal as well. One of them is experimenting with ASCII art. You can display predefined or random messages, play games, or run some animation in ASCII format in the Linux terminal using various command line tools. My teammate Sreenath likes to explore such unusual CLI tools and share his findings with me. I am sharing those findings with you. Most of these programs should be available in the repositories of your Linux distribution. You can use your system’s package manager to install them. To keep the article concise, I have only included the installation instructions for Ubuntu.

1. lolcat: Add colors to your terminal

lolcat

Alright! lolcat doesn’t have anything to do with ASCII art. At least not directly. Still, I included it at the beginning of this article because you can combine other ASCII tools with lolcat. So, what does it do? It is similar to the cat command but it adds random gradient colors to its output. It may not look useful at the moment but you’ll see its impact when the outputs of other ASCII tools are piped through lolcat. Install lolcat with the apt command:

2. Aewan: Display ASCII text beautifully

Aewan is a multi-layered ASCII graphics/animation editor. It produces stand-alone cat-able ASCII art files and an easy-to-parse format for integration into terminal applications. It has two tools: aewan , an ASCII editor and aecat , for viewing the created file. I am not going to discuss the editor part here. aewan initial layoutTo display any text in pretty ASCII format, you need the aecat command. Notice the use of letters in the screenshot below. aewan outputTo install aewan use the following command:

3. Cowsay: Make an ASCII cow say whatever you want

What does the cow say? Whatever you want it to say. The cowsay is already a popular tool among seasoned Linux users. It shows an ASCII cow that repeats the text you provide it. cowsayBut you are not restricted to cows only. You can change it to several other characters as well. Like a dragon (burning King’s landing): cowsayDid you notice the colored output in the above screenshot? That’s the magic of the lolcat command I mentioned earlier. To install cowsay, use:

Читайте также:  Head tail команда линуксе

You can refer to this article for additional configuration and options.

4. jp2a: Convert images into ASCII art

jp2a

jp2a is a command-line tool that converts images to ASCII art in the Linux terminal. It works with JPEG and PNG files. It also allows colored output and your selection of character set to appear as ASCII image. You can install it using the following command:

jp2a --output=ascii.txt --colors input.png

It’s not the only program of this kind. There is ascii-image-converter and several other tools that could be used for the same purpose. I won’t discuss all of them in this list.

5. linuxlogo: Display the ASCII logo your Linux distro

The name says it all. It displays the Linux logo in ASCII format. No, not our beloved Linux logo, Tux but the logo of your Linux distribution. It also shows a few additional information like Linux kernel version, CPU, RAM, hostname, etc. You can install it using the apt command:

sudo apt install linuxlogo

6. Neofetch: Display the Linux logo along with system info

neofetch

The above linuxlogo command is too simplistic. You can amp it up by using Neofetch. It displays the distribution in a more pretty way along with several system information like kernel, uptime, desktop environment, theme, icons, etc. You can also parse it through lolcat to get rainbow-colored output. Install Neofetch using this command:

sudo apt install neofetch

And then just enter neofetch to run the command. There is also screenfetch, a similar tool to Neofetch. You can use either of them.

7. fortune: Get your fortune told

fortune cookie linux

Just kidding! There’s no such thing. However, fortune cookies are still fashionable and apparently, people like to read random predictions or teachings. You can get a similar feature in the Linux terminal with the fortune command: You can install it using the following command:

8. pv: Make things animated

cmatrix

This is a classic example of the unintended use of a Linux command. The pv command is used to monitor the progress of data through pipe. But you can use it to animate the output of any command. Combine it with some of the above-mentioned commands and you can see the ASCII art appearing on your screen as if it is being typed. Don’t get it? Watch this video: You can install it with apt command:

It starts the animation immediately and it keeps on generating random green text falling and disappearing from the screen. The command keeps on running. To stop the running application, use the Ctrl+C keys.

Читайте также:  Linux eth0 no carrier

10. cbonsai: Grow a bonsai in your terminal

Got a green thumb? How about growing an ASCII bonsai tree in the terminal? cbonsai is a fun Linux command that lets you run bonsai tree growing animation in ASCII format. I shared a YouTube Shorts of cbonsai command a few days ago. Can you put these commands to some good use? Not certain about the usability, but you can add some of them in your .bashrc file so that the command is run as soon as you open a terminal session. Many sysadmins do that on shared Linux systems. A program like cowsay or figlet can be used to display a message or system info in a pretty way. You may also use some of these programs in your bash scripts, especially if you have to highlight something. There could be other usages of ASCII art in Linux. I’ll let you share them with the rest of us here.

Источник

Как рисовать сиволами псевдографики в консоли linux СИ

введите сюда описание изображения

вот на винде такую штуку делал (обычные символы Ascii кода) а в линуксе псевдографики вообще нет чтоли? написал такую вот фигню, и вместо знаков ромбы с вопросами

Ответы (3 шт):

Одно из решений — включить в консоли совместимость с кодировкой CP866 Терминал ubuntu это позволяет, собственно это я и сделал Правда это далеко не смое лучшее решение, т.к. в некторых случаях консоль теперь показывает откровенную дич

Также можно работать напрямую с широко-символьными потоками ввода-вывода:

#include #include #include int main()

Проще всего найти нужные символы в таблице Unicode и выводить их в кодировке utf-8.

[email protected]:hashcode$ cat t-utf.c && gcc t-utf.c && ./a.out #include int main (int ac, char *av[]) < // Коды мастей в Unicode: 0x2660 . 0x2667 // 0010 0110 0110 0000 // 0010011001100000 // группируем биты по 6 для перевода в utf-8: 0010 011001 100000 // utf-8: 11100010 10011001 10100000 0xe2 0x99 0xa0 char *cardsuit[8] = ; puts("https://unicode-table.com/ru/#geometric-shapes"); printf("карточные масти: "); for (int i = 0; i < 8; i++) printf("%s", cardsuit[i]); return puts("") == EOF; >https://unicode-table.com/ru/#geometric-shapes карточные масти: ♠♡♢♣♤♥♦♧ [email protected]:hashcode$ 

Кстати, если есть какие-то проблемы с локалью (или вообще с wctomb), то для кодирования символов Unicode с помощью UTF-8 можно использовать вот такую функцию:

// returns utf-8 length (max 4) or 0 if error in ucs // see https://unicode-table.com/en/ int ucs_to_utf8 (unsigned int ucs, char *utf) < if (ucs < 128) < utf[0] = ucs; // ascii return 1; >int l; if (ucs < (1 > 6) | 0xc0; > else if (ucs < (1 > 12) | 0xe0; utf[1] = ((ucs >> 6) & 0x3f) | 0x80; > else if (ucs > 0xe01ef) // not defined yet return 0; else < // 0x10000 . 0xe01ef "Linear B Syllabary" . "CJK Compatibility Ideographs Supplement" . // 11110 0xx 10xxxxxx 10xxxxxx 10xxxxxx l = 3; utf[0] = (ucs >> 18) | 0xf0; utf[1] = ((ucs >> 12) & 0x3f) | 0x80; utf[2] = ((ucs >> 6) & 0x3f) | 0x80; > utf[l] = (ucs & 0x3f) | 0x80; // low 6 bits return ++l; > 

Источник

Оцените статью
Adblock
detector