Make a text blink from a C console application - c

Hello I just got started with C and I don't know much about it, and I was wondering if it was possible to change the font/style/appearence of a text in a console application ?

C has no concept of fonts, styles or other visual representational parameters. Unless you're writing a GUI application, you won't be able to specify anything like that.
Non-GUI application (console applications / CLI applications) that output text will do so by writing to stdout or stderr. The terminal/shell/console application that you're using will "intercept" these streams and display the content (eg. text) accordingly. Therefore, it's up to the terminal/shell/console to apply styling and you have to consult your terminal/shell/console documentation for that.
If you're writing text/terminal-based user interfaces you might want to look at libraries such as ncurses.

You could use ANSI escape codes, if your console supports them.
You could also use higher level libraries, like ncurses.
(and you might consider writing a GUI application, using GTK).
Notice that a RaspberryPi or an Arduino or a Web server (e.g. with lighttpd) can run a C software, and might not even have consoles, fonts, colors...

Related

Cursor control in console display

ANSI.SYS is missing in windows 8.1; so how do I create cursor control in a console display?
I am currently using C; if it cannot be done in C, can it be done in C++? Config.sys is supposed to have DEVICE=ANSI.SYS.
You want to mix the ancient ancient ancient MS-DOS technologies with the modern Windows NT console. ANSI.SYS is missing because it's looong dead.
What you want to do instead is take advantage of the NT console. Here's a starting point in the API documentation. In particular, there's a guide on handling mouse input that you can use as a starting point.
You may find it easier to use a library like Termbox or pdcurses, depending on the type of program you want to write. There are even some text-based user interface (TUI) libraries, such as Turbo Vision, if you want to write that kind of program instead.

Easy way to get a File Picker on Linux

I'm trying to write a small programme that needs to load a few files chosen by the user. I thought it'd be easier to use the Linux system's default file picker rather than write my own, but I literally don't have a clue where to even start looking.
So, can anyone recommend a quick and easy way to use the system's file picker on Linux in C?
As I commented, many Linux systems (e.g. a rented VPS, a consumer router box, ...) don't have any graphical user interfaces (often above X11).
If you want a GUI toolkit in C for Linux, consider using GTK. Then look at GtkFileChooserWidget & GtkFileChooser
If you want a GUI toolkit in C++ for Linux, consider using Qt.
If you want a terminal interface, learn ncurses.
If you want a web interface, use some HTTP server library like libonion or Wt, or make a FastCGI program for your existing web server.
Perhaps coding a simple shell script might be easier. Read Advanced Bash Scripting Guide. You could also use a scripting language like Python, Ruby, Ocaml, ...
If you don't know about Linux programming, read Advanced Linux Programming first. See also intro(2) & intro(3)
... a small program that needs to load a few files chosen by the user.
Just pass them as command-line arguments. It's much easier and doesn't tie you to a given GUI toolkit.
You can easily write a shell wrapper using kdialog on KDE, or dialog if you want curses in a terminal, or ... whatever other tool for whatever other environment.

How to write an application that uses the terminal as GUI? (in C)

I'd like to write an application (in C) that uses the terminal of a *nix OS as its GUI. I mean an application of the kinds of emacs, vi etc. that take up the whole terminal window and jump back to the input prompt after quitting.
How would you go about doing that, preferably in C? Can someone point me to a tutorial covering that?
You need to use ncurses:
http://en.wikipedia.org/wiki/Ncurses
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
It is available on all major distros.
Well, actually this is not GUI (graphic user interface) but a text based interface. You can use the library ncurses to create such applications in C.
Use a library like ncurses, it is specifically designed for this purpose.
Throwing in alternate solutions so that this question thread does not look so monotonic:
the slang library (mc uses it, for example)

Linux/Unix Console Graphics/Control

I would like to know how to create console applications with better control of input and output using C. For example, how does the text-editor nano display the file contents in a certain portion of the screen and then keep a list of commands stationary on the bottom. I know you can use the win32 api to do this in Windows, but what is the Unix/Linux equivalent?
More than likely there's a ncurses interface that controls the screen drawing and placement of items on the screen in a certain position. The api is standard across the linux systems and on unix also, some may be implementation defined depending on the variant of curses used under the commercial variants of unix but otherwise some standard ncurses functionality are compatible.
Besides ncurses and depending on the task at hands you may find newt, a library for color text mode, widget-based user interfaces, a suitable alternative also. Sometimes visual results are better with newt.
If you just want to do the low level stuff, you probably want to use the termcap or terminfo library.
If you want to do it the way nano and just about every other interactive terminal app does it, you probably want to use ncurses. That way you will spend less time implementing terminal control logic, and more time on the actual app you are developing.

Approaches to a GUI for a Large C Program

In our Bioinformatics lab we've recently been asked to create a GUI for a program written (and optimized) in C. Any GUI we designed would need to be able to feed input to and receive output from the C program, while also being easily portable to both Windows and Mac. What are ways to go about doing this?
If your looking for a GUI toolkit that works on windows/mac in C, have you considered GTK?
Download QT or wxWidgets.
Why do the hard work when someone already has and will let you use it for free? I prefer QT myself, btw.
Edit: It does mean using C++ but it will work perfectly with C code.
Use a separate program.
It doesn't break the existing code - especially important if the code has bio knowledge that a programmer might not know/understand/test.
Gui's change often, in a couple of years you are going to be rewriting the gui for NewSuperOsToolkit(tm) but the underlying worker code won't change. We have atmospheric modelling code that I'm sure was originally written in latin.
You keep the ability to run the engine code as a batch, in parallel on MPI in the cloud, and a bunch of other ways you haven't thought of.
You could write the front end GUIs in Java, and have them feed input and receive output from your C programs. I've known a couple of groups here at work that do something similar with C# and C code (but they don't have the multi-platform restraint).
This way you don't necessarily have to create your GUIs using a C toolkit.
Depending on the nature of the program, you could create an entirely separate GUI application (in any language you prefer), and fork/execute the existing program from it, redirecting it's stdin and stdout to your GUI program. Depending on how the existing program works, this could work well, or be very cumbersome.
You could also extend the existing program with GUI code in something like GTK (which has a C API), or you could use Qt (which is C++, but there's usually no problems calling C functions from C++ if you define them as 'extern "C"').
There are a number of scripting with languages that can make this easy. I'd go for tcl/tk it works on mac pretty much out of the box, and is cross platform across pretty much any machine you can think of.
Also GTK is great and a number of scripting languages have bindings for it.
You probably don't want to write your gui in c if you don't have to. use a rapid develoment scripting language.
If you want a native GUI, then go with wxWidgets or QT. (I use wxWidgets ...)
The alternative is to have an HTML based interface using Javascript and CSS. You avoid GUI libraries altogether, you get cross-platform support and the outcome is better on some dimensions, worse on others.
If you really want a standalone user interface, you can integrate it into a binary with something like WebKit.

Resources