Giter Club home page Giter Club logo

Comments (9)

Qix- avatar Qix- commented on June 9, 2024

Let me look into this :)

from better-exceptions.

kdrag0n avatar kdrag0n commented on June 9, 2024

I think this has to do with cmd. Maybe the encoding is messing up the escape sequence, or it needs to output slightly differently on windows?

from better-exceptions.

jcrmatos avatar jcrmatos commented on June 9, 2024

Hello,

My cmd CP is 850.
Python's locale.getpreferredencoding() output is 'cp1252'.

If it helps, on my colorama game I use these (that work) to show color/brightness and change position:

from colorama import init, Style, Fore, Back
DOCK = Style.BRIGHT + Fore.YELLOW + '===' + Style.RESET_ALL
SEA = (Back.BLUE + ' ' * 51 + Back.RESET)
print(Style.BRIGHT + ''.join(items) + Style.DIM)  # show bright items
print('\x1b[%d;%dH' % (line, col))  # set print pos at line, col
print('\x1b[%d;%dH%s' % (line, col, text))  # print text at pos line, col

Best regards,

JM

from better-exceptions.

Qix- avatar Qix- commented on June 9, 2024

Hi - can you try the branch fix-windows-encoding?

The tricky part about this bug is that the ANSI escapes were being encoded, too. This might require a much larger overhaul of output building since we'd still want to encode the text but not the color escapes.

from better-exceptions.

jcrmatos avatar jcrmatos commented on June 9, 2024

from better-exceptions.

Qix- avatar Qix- commented on June 9, 2024

@jcrmatos try

pip install https://github.com/qix-/better-exceptions/archive/fix-windows-encoding.tar.gz

from better-exceptions.

jcrmatos avatar jcrmatos commented on June 9, 2024

Hello,

It uninstalled version 0.1.6 and installed your tgz file.
when I run the following script

import better_exceptions

def a():
    a = 5
    b = 'aaa'
    print(a + b)

a()

it returns these errors

C:\Users\JMatos\OneDrive\JMatos-P\Desktop>python teste.py
Error in sys.excepthook:
Traceback (most recent call last):
  File "C:\Python35-32\lib\site-packages\better_exceptions\__init__.py", line 30
5, in excepthook
    write_stream(full_trace)
  File "C:\Python35-32\lib\site-packages\better_exceptions\__init__.py", line 29
4, in write_stream
    STREAM.buffer.write(data)
TypeError: a bytes-like object is required, not 'str'

Original exception was:
Traceback (most recent call last):
  File "teste.py", line 8, in <module>
    a()
  File "teste.py", line 6, in a
    print(a + b)
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Best regards,

JM

from better-exceptions.

Qix- avatar Qix- commented on June 9, 2024

Alright I'll get to fixing this later today. I'm going to need to fix how ANSI codes are built up.

Thanks for bringing this to my attention :)

from better-exceptions.

ethanhs avatar ethanhs commented on June 9, 2024

With Windows 10 Anniversary update and above, you can

import ctypes
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)

(-11 is the standard out constant, 7 is the new ansi color support)

I put this in my better-exceptions hook, made my console cp65001 by default, and modified __init__.py as such

try:
    PIPE_CHAR.encode(sys.stdout.encoding)
except UnicodeEncodeError:
    PIPE_CHAR = '|'
    CAP_CHAR = '->'

And voila!

from better-exceptions.

Related Issues (20)

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.