Skip to content
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

Replace \x08 with \b #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 2 additions & 6 deletions lab-spinner/spinner_await.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@

import asyncio
import itertools
import sys


async def spin(msg): # <1>
write, flush = sys.stdout.write, sys.stdout.flush
for char in itertools.cycle('|/—\\'):
status = char + ' ' + msg
write(status)
flush()
write('\x08' * len(status))
print('\r' + status, end='', flush=True)
try:
await asyncio.sleep(.1) # <2>
except asyncio.CancelledError: # <3>
break
write(' ' * len(status) + '\x08' * len(status))
print('\r', end='', flush=True)


async def slow_function(): # <4>
Expand Down
8 changes: 2 additions & 6 deletions lab-spinner/spinner_curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@

import curio
import itertools
import sys


async def spin(msg): # <1>
write, flush = sys.stdout.write, sys.stdout.flush
for char in itertools.cycle('|/-\\'):
status = char + ' ' + msg
write(status)
flush()
write('\x08' * len(status))
print('\r' + status, end='', flush=True)
try:
await curio.sleep(.1) # <2>
except curio.CancelledError: # <3>
break
write(' ' * len(status) + '\x08' * len(status))
print('\r', end='')


async def slow_function(): # <4>
Expand Down
8 changes: 2 additions & 6 deletions lab-spinner/spinner_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
import threading
import itertools
import time
import sys


def spin(msg, done): # <1>
write, flush = sys.stdout.write, sys.stdout.flush
for char in itertools.cycle('|/-\\'):
status = char + ' ' + msg
write(status)
flush()
write('\x08' * len(status))
print('\r' + status, end='', flush=True)
if done.wait(.1): # <2>
break # <3>
write(' ' * len(status) + '\x08' * len(status))
print('\r', end='')


def slow_function(): # <4>
Expand Down
8 changes: 2 additions & 6 deletions lab-spinner/spinner_yield.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@

import asyncio
import itertools
import sys


@asyncio.coroutine # <1>
def spin(msg):
write, flush = sys.stdout.write, sys.stdout.flush
for char in itertools.cycle('|/-\\'):
status = char + ' ' + msg
write(status)
flush()
write('\x08' * len(status))
print('\r' + status, end='', flush=True)
try:
yield from asyncio.sleep(.1) # <2>
except asyncio.CancelledError: # <3>
break
write(' ' * len(status) + '\x08' * len(status))
print('\r', end='')


@asyncio.coroutine # <4>
Expand Down