Git Product home page Git Product logo

okbob / pspg Goto Github PK

View Code? Open in Web Editor NEW
2.4K 2.4K 87.0 4.47 MB

Unix pager (with very rich functionality) designed for work with tables. Designed for PostgreSQL, but MySQL is supported too. Works well with pgcli too. Can be used as CSV or TSV viewer too. It supports searching, selecting rows, columns, or block and export selected area to clipboard.

License: BSD 2-Clause "Simplified" License

Makefile 0.43% C 88.12% Shell 0.35% M4 7.29% Roff 3.81%
c csv-viewer dbcli monetdb-client mysql mysql-client ncurses nushell pager postgres-pager postgresql postgresql-client psql terminal terminal-app terminal-pager tui

pspg's People

Contributors

df7cb avatar dk avatar dmfay avatar dmgk avatar ekremkaraca avatar jirutka avatar jonashaag avatar josser avatar jwilk avatar kassandry avatar lbschenkel avatar martint avatar mcclurmc avatar mjbnz avatar mnencia avatar nineinchnick avatar okbob avatar omar-polo avatar pjanx avatar pmav99 avatar rjuju avatar shiar avatar simi avatar sipc-gus avatar talek avatar thedrow avatar theosotr avatar timgates42 avatar titanofold avatar tshirtman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pspg's Issues

Problems with certain commands

If used with \?, the screen is blank (except for the Quit 0..4 C.Freeze) at the bottom. If I press PageDown it's still blank, but when I press it again, I get to see the last 2/3 or 3/4 of the output. I also get a mostly blank screen when using \d on some tables with many columns and constraints/triggers (for example, it only shows the first line of a textsearch trigger, but it does show a blank inverse video, cursor line, that can be moved with the arrow keys).

Versioning problems

The 0.4 tag appears to output 0.3devel when --version is passed.

Additionally, the spec file lists the version as 1.0.0, which seems weird.

error during make

Downloaded 0.6 version.
My linux OS is CentOS 5.11.

I ran configure, no errors there.
Then I ran make and get the following error:

gcc src/pspg.c -o pspg -g -O2   -D_GNU_SOURCE   -lncursesw
/tmp/ccIdvgCz.o: In function `main':
/home/user/Src/pspg-0.6/src/pspg.c:2403: undefined reference to `set_escdelay'
collect2: ld returned 1 exit status
make: *** [pspg] Error 1

An initial google search pointed to ncurses.
I have ncurses version 5.5-24 installed.

Yes, I know my OS is old but it's what I have to deal with.

how to compile

hi there, great project!

However, when I tried to compile:

git clone https://github.com/okbob/pspg.git postgres-pager
cd postgres-pager
make

I got errors about missing files:

pager.c:1:20: fatal error: curses.h: No such file or directory
/usr/bin/ld: cannot find -lncursesw

Some research suggested

sudo apt-get install build-essential libreadline-dev libncurses5-dev libncursesw5-dev

Which somewhat helps, but now I get

gcc -lncursesw pager.c -o pager
/tmp/ccih2jFq.o: In function `initialize_color_pairs':
pager.c:(.text+0x419): undefined reference to `use_default_colors'
pager.c:(.text+0x42d): undefined reference to `init_pair'
pager.c:(.text+0x441): undefined reference to `init_pair'
pager.c:(.text+0x455): undefined reference to `init_pair'
pager.c:(.text+0x469): undefined reference to `init_pair'
pager.c:(.text+0x47d): undefined reference to `init_pair'
/tmp/ccih2jFq.o:pager.c:(.text+0x491): more undefined references to `init_pair' follow
/tmp/ccih2jFq.o: In function `initialize_color_pairs':
pager.c:(.text+0x4af): undefined reference to `assume_default_colors'
pager.c:(.text+0x4c3): undefined reference to `init_pair'
... ... ... ...
pager.c:(.text+0x2a3b): undefined reference to `wrefresh'
pager.c:(.text+0x2aff): undefined reference to `endwin'
collect2: error: ld returned 1 exit status
Makefile:4: recipe for target 'compile' failed
make: *** [compile] Error 1

Any suggestions?

Building on macOS

I was able to build on macOS Sierra by linking against ncurses, instead of ncursesw.

I don't know how to make this a conditional in the Makefile.

history in search

Hi!

I should very much like to ask to add history in searches, like "less" does: one types '/', then can use keys up and down. Thanks for the great product!

/dk

Segfault on \sf

I always get "Segmentation fault" when trying to show SQL function source code using \sf.

Feature request: better handling of zero row results

unpaged result
postgres=# select pid, usename from pg_stat_activity limit 0;
pid │ usename
─────┼─────────
(0 rows)

Time: 1.419 ms
postgres=# select pid, usename from pg_stat_activity limit 1;
pid │ usename
───────┼─────────
22436 │ rms
(1 row)

paged result
postgres=# select pid, usename from pg_stat_activity limit 0;
─────┼─────────
─────┼─────────
(0 rows)
Time: 1.002 ms
postgres=# select pid, usename from pg_stat_activity limit 1;
pid │ usename
───────┼─────────
22436 │ rms
(1 row)

The zero row paged result does not show column names, just the UTF8 border characters. The column names are present in the textual results, and presumably ought to be shown.

Killing PSQL session borks terminal

I had a long-running query that I stopped, using Ctrl-C.

It seems, even though I can't find any processes running pspg that the terminal session is totally bunk. Even typing reset doesn't fix it: the cursor is stuck in column 0.

Problems using UTF8 encoding

It seems that pspg is not capable of printing some special characters such as "á" which is printed as "M-CM-!". The symbol is properly shown using "less".

LANG is set to ca_ES.utf8 and psql encoding to utf8.

Header detection doesn't work with unicode_header_linestyle=single

Example output:

┌────────┬─────────────────────┬───────┬────────┐
│ Schema │        Name         │ Type  │ Owner  │
├────────┼─────────────────────┼───────┼────────┤
│ public │ FROM                │ table │ ilmari │
│ public │ JOIN                │ table │ ilmari │
│ public │ arraytest           │ table │ ilmari │
│ public │ bars                │ table │ ilmari │
└────────┴─────────────────────┴───────┴────────┘

/, Enter to repeat search

In less, if you press / and type a string to search for, you can later press / and then Enter and it will search for the same string again. Pspg should behave this way as well.

Failed to compile

Version : Linux 1ffdea63e0b2 4.13.0-36-generic #40-Ubuntu

gcc -O3 src/pspg.c src/print.c src/unicode.c src/themes.c -o pspg -g -O2   -D_GNU_SOURCE -D_DEFAULT_SOURCE -I/usr/include/ncursesw  -lncursesw -ltinfo
src/pspg.c:157:1: error: conflicting types for 'strcasestr'
 strcasestr(const char *s1, const char *s2)
 ^~~~~~~~~~
In file included from src/pspg.c:19:0:
/usr/include/string.h:368:14: note: previous declaration of 'strcasestr' was here
 extern char *strcasestr (const char *__haystack, const char *__needle)
              ^~~~~~~~~~
Makefile:10: recipe for target 'pspg' failed
make: *** [pspg] Error 1

Grepping the source code revealed that the strcasestr function is never used, but:

  • I am not a real C user
  • I do not want to break things I do not understand

Locally, removing the declaration made the build successful

Mention setting PAGER variable in README

Hi,
I installed this, but then of course nothing happened. It would be great to mention setting PAGER is needed to use this (or maybe there is something else I don't know about ?)

Cheers
S

first column can't be wide

Hi,

i found problem with wide column (output of public key), can be tested with:
--not working (empty screen)
SELECT repeat('A','1000');
--works
SELECT 'a', repeat('A','1000');
--not working
SELECT repeat('A','1000'), 'a';

but maybe caused by some local environment settings...

David

Mangled output with `--quit-if-one-screen`

Output gets mangled when --quit-if-one-screen it's in effect:

$ mysql
[…]
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

user@host/(none)> select now();
+---------------------+
| now()               |
+---------------------+
| 2018-01-28 23:59:24 |
+---------------------+
1 row in set (0.00 sec)

user@host/(none)> ^DBye
$ mysql --pager='pspg --quit-if-one-screen'
[…]
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

user@host/(none)> select now();
+---------------------+| now()               |+---------------------+| 2018-01-28 23:59:46 |+---------------------+1 row in set (0.00 sec)

user@host/(none)> select now()\G
*************************** 1. row ***************************now(): 2018-01-28 23:59:481 row in set (0.00 sec)

user@host/(none)> ^DBye

Thanks

Highlighting search results

Hi,
it would be nice if pspg would highlight search results, both in the current line where the cursor is, but also in other lines, so it's immediately obvious if there are more hits on screen (with possibly more hits to the left or right, but assuming the hits are in one column only, that won't be a problem in practise). less does this by default, see -g and -G, but I'm not sure it needs to be configurable.
Thanks!

Column management

Just an idea of feature request: since pspg is aware of columns in psql output, it could as well allow to:

  1. hide columns from the view - especially usefull for SELECT * queries for wide tables, since there is no "SELECT all_except_specified_columns",
  2. reorder columns - also saves typing of all the column names instead of "*", since PostgreSQL itself doesn't allow to change default order and on-disk structure might be subject of on-purpose alignment,
  3. ellipse specified columns,
  4. show expanded (psql -x) version of the record when selected and (e.g.) ENTER pressed.
  5. provide maximum column width as a command line argument.

User interface:
c - enter column management mode, cursor goes to top-line header, hidden columns are displayed dimmed
left/right arrows - selecting column
h - toggle "hide"
</> - shrink/expand column
m - mark column for "move" operation, left/right arrows to position, enter to accept
c/enter - exit column management mode

Merge top and bottom status line?

Hi,
I'm wondering if the top and bottom status lines couldn't be merged into one line at the bottom. The current top line is right-aligned, and the bottom line is left-aligned, so the content wouldn't have to change much (except when -f is used). This would save one line on the screen and would also match more closely the look of "less".
Thanks!

Brew formula question

Hi! I've created brew formula for your awesome project but there is one small thing I don't know how to handle.

Brew is a package manager for OS X like portage in gentoo or ports in freebsd.
They have a lot of acceptance criteria and one of them is having a test of application for running after compiling.
For small programs they usually check for --help or --version, but this is not considered as a good practice. Better to have some 'real' cases of application usage.
Also, those tests should be non-interactive so CI can run them

So, I've started to write a formula but it's turned out that I can't write any type of test for your app.
I've checked how they usually test other pagers, i.e vimpager: https://github.com/Homebrew/homebrew-core/blob/93a8200c17986038585a140cce4a9bc93e4a3f86/Formula/vimpager.rb

but this approach is not fit for your pager because it bring up interactive interface even if there is not enough content for paging.
Also, you don't have --version or --help.

So, i've created this #27

I have never write any line of C, but I hope there is nothing wrong with this few lines.
If you accept PR, please, do a release so I can update brew formula with new version (0.3?)

Thank you and sorry if my english is not good )

describe what an "alternate screen" is for -X option

Thanks for pspg. I've just started using it and it looks promising.

I was reading through the man page and also the recommended .psqlrc configs and noticed "-X" in the configuration. I don't know what alternate screen the documentation is referring to. I've looked at the source code and can't make sense of it either.

Would you consider expanding the documentation a bit with regards to "alternate screen" ?

Thanks again!

-m

"Save content to file" command creates zero-byte files

PSPG works beautifully for me except for the "Save content to file" command. After entering a filename, it returns the message "Cannot write to [filename]" and creates a zero-byte file at the specified path.

Actually, this has been the case for me for all builds since 2017/09 (I just git-pulled and recompiled it again today).

I'm invoking PSPG in my .psqlrc like so:

\setenv PAGER 'pspg -s 11 -X --no-mouse --no-sound'

...and running it on OSX 10.12.16 with psql 9.4.0.

Any ideas? Thanks!

Value width miscalculated

PAGER="./pspg -s 11 -g -i -F" psql -c "SELECT (CASE WHEN random()<0.5 then 'ó' else '-' END),md5(random()::text) FROM generate_series(1,80)"

generates following output (note the misalignments):

 ó    |973263148f6c1da850c5b82f44bedd
 -    | 98d546af5b4f08861a8e0291b3117c22
 ó    |3e7a73ef2ae53719d7a5eaa88b6f41
 ó    |9a48e5cb0b378cbc9c72721c983adb
 -    | 0d5c73047d42b16a3ab7f09a845f1fe2
 -    | 087f7bc9a684617fc9c5522c0ee79fef
 -    | 81db99d85a7c63dc447b5675a0774bbb
 ó    |f00ab7b5e450eb314d8b9f1e4875db
 -    | 2ca1b394e873b1168c0e4eac829ac7ca

This happens with 8-bit (non unicode) locale (ISO8859-2 in my case).

Edit: it's better visible with constant value in 2nd column ("abcdef"):

 -    | abcdef
 ó    |cdef
 -    | abcdef
 ó    |cdef
 -    | abcdef
 -    | abcdef
 ó    |cdef

Sementation fault on 'G'

pspg segfaults when pressing G for this input:

 id 
----
 0
 0
  
 0
 0
 0
 0
 0
 0
 0
(10 rows)

Used ncurses version is 6.1.

Compilation again

I saw you released a new version with resizing implemented, so I got excited and tried

git clone https://github.com/okbob/pspg.git postgres-pager
cd postgres-pager
sudo apt-get install build-essential libreadline-dev libncurses5-dev libncursesw5-dev
gcc pager.c -o pager -L. -lncursesw
./pager -d

as per #1, but got

pager.c: In function ‘main’:
pager.c:1641:26: error: ‘BUTTON5_PRESSED’ undeclared (first use in this function)
       if (event.bstate & BUTTON5_PRESSED)
                          ^
pager.c:1641:26: note: each undeclared identifier is reported only once for each function it appears in

instead. I'm using commit e0a0aba17 here. Any suggestions?

supporting non-color terminals

To support non-color terminals, I would suggest to evaluate the 'b' command line switch (black-withe style):

Line 2414: if(!has_colors()) -> if(!has_colors() && style != 0)

cannot to reopen stdin: No such device or address

When running psql with su:

su postgres -c "psql test"

I get the following error:

Line style is unicode.
Border style is 2.
Pager is used for long output.
Timing is on.
Null display is "¤".
psql (10.1)
Type "help" for help.

test=# select * from test;
cannot to reopen stdin: No such device or address
Time: 14.278 ms
test=#

explain parameters

entering a invalid parameter
Usage: ./pspg [-b] [-s n] [-c n] [-f file] [-X]
is printed on the screen.

What are this for parameters and what are they good for. I couldn't find anything in the README.md

Add more key commands like less: ^E ^Y ^D ^U

More key commands that many less users will naturally reach for:

  • ^E scroll window down one line, keeping cursor in place
  • ^Y scroll window up one line, keeping cursor in place
  • ^D forward a half window
  • ^U backward a half window

Crashes on strings with newlines

# select * from newline;
  t  
─────
 foo↵
 bar
(1 Zeile)
# \pset pager always

... then do the select again, and search for /foo:

Segmentation fault (core dumped)

Core was generated by `pspg -b --less-status-bar --ignore-case'.
Program terminated with signal SIGSEGV, Segmentation fault.
(gdb) bt
#0  __strstr_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strstr-sse2-unaligned.S:40
#1  0x0000557cecc9fedb in window_fill (window_identifier=3, srcy=<optimized out>, srcx=0, cursor_row=0, desc=0x7ffe2ed3f740, 
    scrdesc=0x7ffe2ed3f200, opts=0x7ffe2ed3f1d4) at src/print.c:136
#2  0x0000557cecc9b540 in main (argc=<optimized out>, argv=<optimized out>) at src/pspg.c:1571

Please let me know if you need more details to reproduce. Thanks!

Error on RedHat 6.8

# ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for ncursesw via pkg-config... yes
checking for working ncursesw/curses.h... yes
checking for working ncursesw.h... no
checking for working ncurses.h... yes
configure: creating ./config.status
config.status: creating config.make
# make
gcc -O3 src/pspg.c src/print.c src/unicode.c src/themes.c -o pspg -g -O2      -lncursesw
src/pspg.c: In function ‘get_code’:
src/pspg.c:1388: warning: passing argument 1 of ‘tigetstr’ discards qualifiers from pointer target type
/usr/include/curses.h:792: note: expected ‘char *’ but argument is of type ‘const char *’
#

What to do?

Feature request: disable mouse support

It's nice to be able to mark text for copy. On my linux workstation, mouse control only selects the active row which is not a good tradeoff on balance; it would be nice to have command switch to let O/S handle all mouse activity...thanks

Compilation again (sorry)

Cloning the newest sources (7ed50cb), I sadly get pager.c:20:26: fatal error: ncurses/term.h: No such file or directory:

$ sudo apt-get update
$ sudo apt-get install build-essential libreadline-dev libncurses5-dev libncursesw5-dev
build-essential is already the newest version (12.1ubuntu2).
libncurses5-dev is already the newest version (6.0+20160213-1ubuntu1).
libncursesw5-dev is already the newest version (6.0+20160213-1ubuntu1).
libreadline-dev is already the newest version (6.3-8ubuntu2).

$ gcc pager.c -o pager -L. -lncursesw                                                  
pager.c:20:26: fatal error: ncurses/term.h: No such file or directory
compilation terminated.

Update Looks like I can comment out line 20, which compiles...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.