1

I want to use setfillstyle() and textcolor() in UBUNTU(terminal) .

But I found on internet that it is store in conio.h library which cannot be used in UBUNTU .

So what should I do ?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Koolman
  • 127
  • 1
  • 8
  • 2
    I removed your 2nd question about `inportb`. If you want to ask about that, ask a separate question. You should probably tell what you want to do, show how you would do it in MSDOS using `inportb`, and ask how to do it Ubuntu (because the way to do it will be totally different, or it may even be impossible without writing a kernel driver...). – hyde Oct 25 '17 at 06:39

4 Answers4

1

The de facto way to do these things on unixy terminals today is to use some Curses libray, which on Ubuntu is Ncurses library developed by GNU Project.

Google for "ncurses tutorial" to get started. It is different from conio.h, so just learn it from scratch.

hyde
  • 60,639
  • 21
  • 115
  • 176
  • in Curses what would be the function which is alternative for 'setfillstyle' and 'textcolor' – Koolman Oct 25 '17 at 07:39
  • @Koolman I think it is `attron`. But the whole library is a bit different. Instead of thinking which function corresponds to which function, you're better off thinking in terms of "this is how I display something using conio.h, how do I achieve same display using ncruses?" – hyde Oct 25 '17 at 07:48
1

That's true. setfillstyle and textcolor are functions of the old conio MS/DOS library. It can only be used nowadays in Windows consoles (unless you manage to use a real MS/DOS or FreeDOS...).

If you want to use color effect in a Linux terminal window, you could have a look at curses which normally exists in Ubuntu and allows to create portable programs.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
0

First of all, controlling a "screen" (or however you want to call it) is not in the scope of C. C I/O (stdio.h) only operates on input and output streams. Therefore, you either have to write platform-specific code yourself or use a library.

About conio.h, as other answers already state, this is an obsolete header. It was created for MS-DOS (AFAIK by Borland for their TurboC product) and as a result is by design strongly coupled to what a typical PC in textmode with BIOS routines provides. Although you probably find some implementations of it for other systems than MS-DOS, I'd strongly recommend not to use it.

The de facto standard nowadays for controlling a console/terminal is indeed curses, which first emerged on Unix systems. It was part of a commercial system, but free implementations for a variety of systems exist. Using curses, your code will be portable to many systems, including virtually all *nix derivates as well as Windows.

Two implementations of curses are very widespread:

  • ncurses from the GNU project, this is portable to many *nix systems and more recently to windows as well (I'd recommend it for Linux, FreeBSD etc.)

  • pdcurses which is portable as well, but with a focus on DOS and Windows (I'd recommend it for Windows)

For learning how to use curses, the NCURSES Programming HOWTO is a great resource. I personally recommend to #include <curses.h> everywhere this HOWTO suggests #include <ncurses.h>, so your code can be used with other curses implementations without modification.

  • in Curses what would be the function which is alternative for 'setfillstyle' and 'textcolor' – Koolman Oct 25 '17 at 07:42
  • @Koolman there's no 1:1 mapping, you should really work through the HOWTO. –  Oct 25 '17 at 10:16
0

As suggested, ncurses is the usual place to start looking with Ubuntu.

According to this page

setfillstyle function sets the current fill pattern and fill color.

and goes on to list the available fill-styles:

enum fill_styles 
{ 
   EMPTY_FILL, 
   SOLID_FILL, 
   LINE_FILL, 
   LTSLASH_FILL, 
   SLASH_FILL,
   BKSLASH_FILL, 
   LTBKSLASH_FILL, 
   HATCH_FILL, 
   XHATCH_FILL, 
   INTERLEAVE_FILL,
   WIDE_DOT_FILL, 
   CLOSE_DOT_FILL, 
   USER_FILL 
};

There's no portable equivalent to the fill pattern (it's dependent upon the terminal type). Depending on what you want, <conio.h> is used for coloring full-screen or command-line applications. With the latter, you have tput (a curses utility), which can set foreground and/or background colors.

For the former, ncurses implements the X/Open background character, which can be used in full-screen applications to provide a combination of a fill-character and/or color. You could imitate conio's fill-style using the background character (though I haven't seen anyone make a table of corresponding Unicode values for those). EMPTY_FILL is easy: just a space character.

Further reading:

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105