how to restore default characteristics of terminal in fpc program (+ crt library)? - pascal

Default terminal characteristics (on Linux mint) are: black background and grey font. After launching fpc program with TextColor(Red) and TextBackground(White) and quit out of a program, terminal still has red font and white background.
The goal is to find a solution which will restore default characteristics (black background and grey font) of terminal.
thanks for your attention

The easiest solution is to set the text background and text color back to black/grey programatically, using TextColor and TextBackground before end.

the solution is not pretty nice, but worked (from here: https://wiki.freepascal.org/Executing_External_Programs#TProcess).
you should paste the code to the relevant places in a program:
uses
process;
var
reset_process: TProcess;
begin
reset_process := TProcess.Create(nil);
reset_process.Executable := 'reset';
reset_process.Options := reset_process.Options + [poWaitOnExit];
reset_process.Execute;
reset_process.Free
end.

Related

Foreground and background color rendered differently in macOS Terminal.app

I tried to build some simple custom prompt for zsh inspired by the 'powerline look'. My .zshrc currently looks like:
CLICOLOR=1
PROMPT=$'%K{236}%F{246}%n%f#%B%m%b %k%K{045}%F{236}\Ue0b0%f %F{000}%2~%f %k%F{045}\Ue0b0%f %# '
However, I noticed color differences between the background color of the path and the foreground color of the following triangle (both set as 045), as can be seen in the following screenshot
I thought that something is wrong with my PROMPT variable, but the prompt looks fine in the terminal inside VSCode:
It seems as if Terminal.app is darkening the background color for some reason, but I don't find a way to turn this off.
Is this possible or can I modify my PROMPT in some way that prevents the problem?
EDIT: I use the font "Hack" that can be found here: https://sourcefoundry.org/hack/
Thanks in advance,
Philipp
The problem is that the MacOS Terminal app has a weird feature where it renders text against the terminal's default background differently. If a background color is explicitly specified then the foreground colors are all slightly different to what they are when there is no background color specified or it has been reset to default.
This is the same issue as below. Check there for better discussion and a potential workaround. https://apple.stackexchange.com/questions/282911/prevent-mac-terminal-brightening-font-color-with-no-background/446604#446604

terminal top command different text colors

on OSX, when I run top sometimes I see some different colors, namely black text....
What does it mean?
What bash setting do I need to change to make these a different color? black is too hard to read with my setup.
It turns out that it was a simple text color in the terminal preferences, I think the title of the setting was 'bold text'

Changing the text and background color of a PDF file

I'd like to change the background color and text color programmatically in PDF documents so that they're nicer to read at night (kinda like in Adobe Reader: Edit -> Preferences -> Accessibility -> Replace Document Colors).
Is there any good command line tool or API for Windows that can do that?
So far I haven't found any. It's OK if it needs to save the newly colored PDF into a new file.
There is no way to do this directly, with no (Free Software or gratis) tool I'm aware of. (Because in the general case, you'll have to change all colors of the PDF pages, not just the background alone, so you can still have some contrast and color differences.)
What you describe for Adobe Reader does not change the PDF file itself, it changes the way the application renders the pages (by inverting colors, or similar). The PDF remains the same during and after viewing it.
However, you might be able to achieve a similar thing by applying a suitable ICC color profile to the input PDF and produce, with the help of (a very recent version of) Ghostscript, a new output PDF from this.
The question would remain: what IS a "suitable" ICC color profil for your purpose??
I've shortly considered to apply a gray-ish background to the PDF with the help of pdftk ... background ... command line. But this would probably make some or many PDFs unreadable. (A black background would surely make it unreadable, because most text is black and would remain so.)
To create a PDF page (A4 size) which could serve as the gray background, you could use Ghostscript: gs -o gray.pdf -sDEVICE=pdfwrite -g5950x8420 -c ".8 setgray 0 0 595 842 rectfill showpage".
Then apply it to your original PDF (A4): pdftk original.pdf background gray.pdf output orig-with-backgr.pdf.
Note, this will only change the background of these pages (or those areas of pages), where the original background is transparent, as most text-based PDFs are. It will not work for pages or areas where the background is opaque white or color.)
You can also achieve a permanent color change (inverse colors) quite easily with the help of ImageMagick. But this will at the same time munch and make mincemeat of your nice vector PDFs, converting them into complete-raster image pages: convert nice.pdf -alpha off -invert inverted-colors-ugly-raster.pdf.
Finally, here is a rather unreliable way to accomplish the inverting of colors with the help of Ghostscript. It sets up a colortransfer function for the output PDF file:
gs -o output.pdf \
-sDEVICE=pdfwrite \
-c "{1 exch sub}{1 exch sub}{1 exch sub}{1 exch sub} setcolortransfer" \
-f input.pdf
It is unreliable, because not every PDF viewer will honor that setting. I've tested it a few times in the past...
These viewers DO SHOW inverted colors:
Adobe Reader
Adobe Acrobat
gv
Ghostscript/gs
Chrome's native PDF renderer ('pdfium')
These ones DON'T SHOW inverted colors:
Chrome with PDF.js
Firefox with PDF.js
Zathura
MuPDF
Just in case the OP doesn't really need to change the PDF document colors permanently, but only wants a PDF viewer other than Acrobat that can do similarly change the displayed colors...
MuPDF: MuPDF is a lightweight PDF viewer (amongst other things). It can invert the displayed colors with the simple stroke of the i for any document while it is open. MuPDF is also available for Windows (and iOS, and Android, and OSX, and Linux). (It is made by the same company which brought us Ghostscript).
MuPDF screenshots here: "normal" view (left) and "inverted" view (right)
SumatraPDF: This is a very popular alternative PDF viewer for Windows. Its PDF rendering engine is based on MuPDF. Hitting . in presentation mode, it changes background to black. Hitting w in presentation mode, it changes background to white. (I don't think it can also invert all colors, but I do not have the latest release available right now to check.) For startup adding -invert-colors to the command line, it will invert the colors for the rendered document.
Zathura: A lightweight PDF viewer for Linux and OSX, which can be controlled by Vim-like keyboard shortcuts. ctrl+r will re-color the rendering of any opened document. Background will change to dark, texts will change to bright gray (however it will not invert a, say blue text to yellow, like MuPDF does). I'm not sure if it is available on Windows too.
Evince: The Gnome PDF viewer, available for Linux, OSX and Windows. It can invert the colors of the open document too; the keyboard shortcut is ctrl+i.
XPDF: XPDF is quite an ancient PDF viewer for Unix + Linux (not sure if there is a Windows version available -- maybe in Cygwin). It has a startup option in its command line: xpdf -rv -papercolor "#333333" file.pdf will invert the colors (-rv is for reverse video, -papercolor lets you change the background to something different from pure black [as any inverted white would become]).
As you asked for an API, I'll throw one additional possibility in the mix. It is actually possible to write a plug-in for Adobe Acrobat (should be possible for Adobe Reader too, but Reader plug-ins are more difficult) that interferes with display.
A long time ago I wrote code for Enfocus PitStop to implement a wireframe rendering mode for PDF files inside of Adobe Acrobat. Click a button and the display changes to wireframe, click again and you have your normal view. This works because you can (as a plug-in) modify the display list (the list of objects) drawn by Acrobat.
This means that to draw your special display mode you could create a new display list (or modify the existing one) so that it has a rectangle at the very back in the color that you want and then modify the color of all objects in the display list to suit your needs.
This is relatively complex as it is, what makes it more complex is that - if you don't want your changes to affect the PDF file on disk, you have to intercept a myriad of Acrobat notifications and undo your changes. For example, if the user attempts to save the PDF document while viewing in your display mode, you have to make sure you are warned about that and undo the changes during the save. Adobe Acrobat makes this possible because it sends you notifications before and after the save process but it's still a serious job to make sure nothing gets screwed up.
But it's a absolutely cool and very flexible way to implement what you were after. Just make sure you have more than a couple of weeks to implement it :)
Install nodejs.
npm i -g serve
In directory with pdfs run: serve
Open http://localhost:5000 in Chrome and click on some file.
Install Chrome extension Dark Reader
Dark Reader > Toggle localhost:5000

Two color mode for emacs - no colors / monochrome

I dont like colors. How can I tell emacs to
stick to just black and white for everything.
Higlighted text or the mode line can be
shown in reverse video (black text on white background)
I'm using Emacs 24 on windows under cygwin
in console mode.
I tried,
TERM=xterm-mono emacs --no-splash
which gives
emacs: Terminal type xterm-mono is not defined.
Also
emacs --no-splash --reverse-video
which shows some blues and some other colors too.
I already have the following in my .emacs:
(setq-default global-font-lock-mode nil)
(set-face-foreground 'mode-line "white")
(set-face-background 'mode-line "black")
M-x customize-face seems interesting but there's about
300 lines of options and I dont feel like changing that
many lines.
Disabling font-lock should get rid of most colours. Try this in your configuration:
(global-font-lock-mode -1)
I don't have Cygwin to test on, but it gives me white on black in a Linux terminal with emacs -nw.
Hmm... I don't like colors very much either, but the way I did it is to only change those faces that bothered me. I.e. go to a chunk of text with a color you don't like, then use M-x customize-face there (which should give you as default the face used for that color) and change that one (or if it inherits from another, you might prefer to change the one from which it inherits).
While there are hundreds of faces, in my experience, you can start by changing a small dozen.

Change default program output colors on mac terminal

I don't know if this is the right place to post this question, but here goes:
I recently (less than a year ago) made the switch to a mac from my ubuntu setup. One of the first things I changed was terminal.app's background color and opacity. In my old setup, it was a semi-transparent, black window, which I would put on top of other windows, so I could see the code on it, as well as look through it at the window under it. terminal.app on my mac looks like this now. This is great… except when I have to use programs like sphinx or look at man pages.
Some programs have outputs in black font; man pages have entries in black font. Since the background of my terminal.app is also black, this font is rendered almost invisible (seen in the two screenshots below):
Is there any way that I can tell terminal.app to display all black text as some other color?
Isn't that in Terminal's Preferences ?

Resources