Skip to content

Some big changes for a potential Version 4 (windows support and better testing) #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cd19748
Merge pull request #69 from vanschelven/master
vanschelven Jan 8, 2022
47f145a
general cleanup of config and settings files
Cube707 Feb 6, 2022
28ab4d6
seperate platforms and other improvments
Cube707 Jan 26, 2022
1f251d6
pytest setup for test on multiple platforms and windows tests
Cube707 Jan 26, 2022
f399db5
windows actually uses LF for ENTER
Cube707 Feb 6, 2022
493da65
github workflow for both platforms
Cube707 Feb 6, 2022
2e973e0
bump precommit-hook versions
Cube707 Apr 29, 2022
bc94d30
removed python 3.5 and pypy support
Cube707 Apr 29, 2022
1cb6462
simplyfied .yamellinter.yaml
Cube707 Apr 29, 2022
77e3d11
add end-of-line-fixer to pre-commit
Cube707 Apr 29, 2022
38e0e8f
fix linux tests and fix for linux readkey to read all keys
C0D3D3V Apr 29, 2022
07cca72
fix __all__
C0D3D3V Apr 29, 2022
47e22bd
Fix BACKSPACE Keycode on Linux
C0D3D3V Apr 29, 2022
5ff7289
Reorder Windows Keycodes and add CTRL_A to CTRL_Z to windows Keycodes
C0D3D3V Apr 29, 2022
19a330a
added DELETE in addition to SUPR
Cube707 Apr 29, 2022
b76043c
replace redundant codes with reference to existing vars
Cube707 May 1, 2022
507686a
fix function keys f5 to f12
C0D3D3V May 4, 2022
fdd3d0f
Merge pull request #4 from C0D3D3V/fix_function_keys
Cube707 May 5, 2022
ccd4838
only import platfrom from sys, not full package
Cube707 May 3, 2022
95ea9d8
enable mac support
Cube707 May 3, 2022
a307338
romoved unused var ESCAPE_SEQUENCES from linux_key
Cube707 May 5, 2022
9fbd906
added testscript
Cube707 May 5, 2022
367bb56
replace redundant CTRL_H code with reference to BACKSPACE
Cube707 May 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

10 changes: 7 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: Pytests

on:
push:
Expand All @@ -17,11 +17,14 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
python-version:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
Expand All @@ -38,6 +41,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements-test.txt
python -m pip install -e .
- name: Test with pytest
run: |
pytest
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
repos:

- repo: https://github.com/adrienverge/yamllint
rev: v1.26.3
hooks:
- name: check YAML format
id: yamllint

- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- name: re-format with black
id: black
Expand All @@ -17,14 +19,11 @@ repos:
hooks:
- name: remove whitespaces
id: trailing-whitespace
- name: add newline to end of files
id: end-of-file-fixer

- repo: https://gitlab.com/pycqa/flake8
rev: 21d3c70d676007470908d39b73f0521d39b3b997
rev: 4.0.1
hooks:
- name: check-format with flake8
id: flake8
args:
- --show-source
- --statistics
- --count
- --max-complexity=12
7 changes: 4 additions & 3 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
extends: default

ignore: |
.github/workflows/*
venv/*

rules:
truthy:
ignore: |
.github/workflows/*
indentation:
spaces: 2
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
all: precommit test
all: test precommit

test:
python setup.py test
@pytest

precommit::
pre-commit run -a
precommit:
@pre-commit run -a

publish:
@python setup.py bdist_wheel upload
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Installation

pip install readchar

The :code:`readchar` library works with python 2.7, 3.4, 3.5, 3.6 and Pypy.
The :code:`readchar` library works with python 3.6, 3.7, 3.8 and 3.10.

Usage
-----
Expand Down
16 changes: 13 additions & 3 deletions readchar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
from . import key
from .readchar import readchar, readkey
from sys import platform

__all__ = [readchar, readkey, key]

if platform.startswith("linux") or platform in ("darwin"):
from .read_linux import readchar, readkey
from . import key_linux as key
elif platform in ("win32", "cygwin"):
from .read_windows import readchar, readkey
from . import key_windows as key
else:
raise NotImplementedError(f"The platform {platform} is not supported yet")


__all__ = ["readchar", "readkey", "key"]
98 changes: 0 additions & 98 deletions readchar/key.py

This file was deleted.

76 changes: 76 additions & 0 deletions readchar/key_linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-

# common
LF = "\x0a"
CR = "\x0d"
ENTER = LF
BACKSPACE = "\x7F"
SPACE = "\x20"
ESC = "\x1b"
TAB = "\x09"

# CTRL
CTRL_A = "\x01"
CTRL_B = "\x02"
CTRL_C = "\x03"
CTRL_D = "\x04"
CTRL_E = "\x05"
CTRL_F = "\x06"
CTRL_G = "\x07"
CTRL_H = "\x08"
CTRL_I = TAB
CTRL_J = LF
CTRL_K = "\x0b"
CTRL_L = "\x0c"
CTRL_M = CR
CTRL_N = "\x0e"
CTRL_O = "\x0f"
CTRL_P = "\x10"
CTRL_Q = "\x11"
CTRL_R = "\x12"
CTRL_S = "\x13"
CTRL_T = "\x14"
CTRL_U = "\x15"
CTRL_V = "\x16"
CTRL_W = "\x17"
CTRL_X = "\x18"
CTRL_Y = "\x19"
CTRL_Z = "\x1a"

# ALT
ALT_A = "\x1b\x61"

# CTRL + ALT
CTRL_ALT_A = "\x1b\x01"

# cursors
UP = "\x1b\x5b\x41"
DOWN = "\x1b\x5b\x42"
LEFT = "\x1b\x5b\x44"
RIGHT = "\x1b\x5b\x43"

CTRL_ALT_SUPR = "\x1b\x5b\x33\x5e"
CTRL_ALT_DELETE = CTRL_ALT_SUPR

# other
F1 = "\x1b\x4f\x50"
F2 = "\x1b\x4f\x51"
F3 = "\x1b\x4f\x52"
F4 = "\x1b\x4f\x53"
F5 = "\x1b\x5b\x31\x35\x7e"
F6 = "\x1b\x5b\x31\x37\x7e"
F7 = "\x1b\x5b\x31\x38\x7e"
F8 = "\x1b\x5b\x31\x39\x7e"
F9 = "\x1b\x5b\x32\x30\x7e"
F10 = "\x1b\x5b\x32\x31\x7e"
F11 = "\x1b\x5b\x32\x33\x7e"
F12 = "\x1b\x5b\x32\x34\x7e"

PAGE_UP = "\x1b\x5b\x35\x7e"
PAGE_DOWN = "\x1b\x5b\x36\x7e"
HOME = "\x1b\x5b\x48"
END = "\x1b\x5b\x46"

INSERT = "\x1b\x5b\x32\x7e"
SUPR = "\x1b\x5b\x33\x7e"
DELETE = SUPR
84 changes: 84 additions & 0 deletions readchar/key_windows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

# common
LF = "\x0a"
CR = "\x0d"
ENTER = CR
BACKSPACE = "\x08"
SPACE = "\x20"
ESC = "\x1b"
TAB = "\x09"

# CTRL
CTRL_A = "\x01"
CTRL_B = "\x02"
CTRL_C = "\x03"
CTRL_D = "\x04"
CTRL_E = "\x05"
CTRL_F = "\x06"
CTRL_G = "\x07"
CTRL_H = BACKSPACE
CTRL_I = TAB
CTRL_J = LF
CTRL_K = "\x0b"
CTRL_L = "\x0c"
CTRL_M = CR
CTRL_N = "\x0e"
CTRL_O = "\x0f"
CTRL_P = "\x10"
CTRL_Q = "\x11"
CTRL_R = "\x12"
CTRL_S = "\x13"
CTRL_T = "\x14"
CTRL_U = "\x15"
CTRL_V = "\x16"
CTRL_W = "\x17"
CTRL_X = "\x18"
CTRL_Y = "\x19"
CTRL_Z = "\x1a"

# Windows uses scan codes for extended characters. This dictionary
# translates the second half of the scan codes of special Keys
# into the corresponding variable used by readchar.
#
# for windows scan codes see:
# https://msdn.microsoft.com/en-us/library/aa299374
# or
# https://www.freepascal.org/docs-html/rtl/keyboard/kbdscancode.html

# cursors
UP = "\x00\x48"
DOWN = "\x00\x50"
LEFT = "\x00\x4b"
RIGHT = "\x00\x4d"

# other
ESC_2 = "\x00\x01"
ENTER_2 = "\x00\x1c"
F1 = "\x00\x3b"
F2 = "\x00\x3c"
F3 = "\x00\x3d"
F4 = "\x00\x3e"
F5 = "\x00\x3f"
F6 = "\x00\x40"
F7 = "\x00\x41"
F8 = "\x00\x42"
F9 = "\x00\x43"
F10 = "\x00\x44"
F11 = "\x00\x85" # only in second source
F12 = "\x00\x86" # only in second source

# don't have table entries for...
# ALT_[A-Z]
# CTRL_ALT_A, # Ctrl-Alt-A, etc.
# CTRL_ALT_SUPR,
# CTRL-F1

PAGE_UP = "\x00\x49"
PAGE_DOWN = "\x00\x51"
HOME = "\x00\x47"
END = "\x00\x4f"

INSERT = "\x00\x52"
SUPR = "\x00\x53"
DELETE = SUPR
Loading