reddocmd / cork Goto Github PK
View Code? Open in Web Editor NEWA command-line calculator for hex-lovers.
License: GNU General Public License v2.0
A command-line calculator for hex-lovers.
License: GNU General Public License v2.0
The welcome message is cute:
$ cork
Welcome to cork - a calculator for hex-lovers!
Press Ctrl + D to exit.
cork>
but is far from being crucial: there should be a way to disable it, if desired.
A good way would be through an option in a config file (see #2).
It's nice to be able to set
of
to another base but is still a bit verbose, in particular when done for a single operation.
Could cork be extended to support an operator that temporarily switches of
to what makes sense in a "do what I mean" manner?
For example, the ?
operator could result in hex values being printed as decimal and decimal as hex, irrespective of of
. Consider
cork> set of dec
cork> 1 + 1
2
cork> 42?
0x2a
cork> set of hex
cork> 0x10 + 0x10
0x20
cork> 0x100?
256
instead of having to manually manage of
:
cork> set of hex
cork> 42
0x2a
cork> set of dec
cork> set of dec
cork> 0x100
256
cork> set of hex
I can't decide whether ?
's behavior should be dependent on of
, though ...
If support for more niche bases is desired (or to disambiguate complex expressions), ?
could also take an optional right operand that represents the requested base:
cork> set of hex
cork> 0x20 + 3
0x23
cork> 0x20 + 3?
Failed to parse "0x20 + 3?": --> 1:9
|
1 | 0x20 + 3?
| ^---
|
= ambiguous expression, expected right operand for base
cork> 0x20 + 3?b
0b100011
cork> 0x20 + 3?d
35
Another approach could also be to overload the case of receiving a single literal of the current of
by reflecting it in the alternative base:
cork> set of hex
cork> 0x100
256
cork> set of dec
cork> 256
0x100
which is definitely more informative than the current behavior:
cork> set of hex
cork> 0x100
0x100
cork> set of dec
cork> 256
256
If worth the added complexity, support for other alternative bases than the respective "default ones" (i.e. hex for decimal and decimal for hex), could be implemented through a new set
property. For example:
cork> set of hex
cork> set alter_of bin
cork> 0x100
0b100000000
-c
--config
Hi, here in Windows I'm building the v0.2.6 and shows:
warning: field `0` is never read
--> src\expression.rs:46:25
|
46 | pub struct ParseOpError(String);
| ------------ ^^^^^^
| |
| field in this struct
|
= note: `ParseOpError` has a derived impl for the trait `Debug`, but this is intentionally ignore
d during dead code analysis
= note: `#[warn(dead_code)]` on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the f
ield numbering, or remove the field
|
46 | pub struct ParseOpError(());
| ~~
warning: `cork` (bin "cork") generated 1 warning
Finished release [optimized] target(s) in 0.44s
Cheers.
I'd like to be able to specify multiple output formats, e.g.
set of hex bin dec
so that each answer is displayed in these radixes:
cork> 10+2
0xb 0b1011 12
Ideally with a nice tabulated/table output, e.g.
----------------------------
| 0xb | 0b1011 | 12 |
-----------------------------
For readability of the numbers, it is sometimes desired to add separators to long numbers (for example, writing 0x3000_0000
to avoid confusion with 0x3000000
or 0x300000000
); could this be supported by cork? As long as those separators aren't valid operators, it should simply mean stripping arguments from expected separators before converting them to integers.
As an illustration, consider the following:
cork> 0x3000_0000 + 0x200_0000
Failed to parse "0x3000_0000 + 0x200_0000": --> 1:7
|
1 | 0x3000_0000 + 0x200_0000
| ^---
|
= expected EOI, add, subtract, multiply, divide, rem, lshift, or rshift
Although this is requested for hex numbers, I guess it would also be valid for other bases and characters other than _
: for example 10'000'000
, 10,000,000
? The hex case being the most interesting, of course.
Lines are interpreted the same way if they had been typed in.
Evaluated in order, expressions give outputs. Set directives
are evaluated, but emit no output.
Hi, it would awesome if were possible to make direct operations on a single line, so it can be used with a batch file, something like:
cork 0x4DEE72 + 0x18CF5 >filename.txt
Actually it outputs :
error: Found argument '0x4DEE72' which wasn't expected, or isn't valid in this context
USAGE:
cork [OPTIONS]
For more information try --help
Cheers
Define the format for a file holding the user's configuration preferences and implement the logic to read and parse that file at start-up.
Preferably, the file should be expected to be found under ${XDG_CONFIG_HOME}/cork/
, as per the XDG Base Directory Specification.
Cork currently ignores command-line arguments; instead, it could be extended to accept an expression, compute and print it, and exit.
For example:
$ cork 0x10 + 0x10
0x20
$ cork
Welcome to cork - a calculator for hex-lovers!
Press Ctrl + D to exit.
cork> 0x10 + 0x10
0x20
cork>
(note that, in the first case, cork returns immediately)
Instead of just having ans
for the last answer, why not memorize all the answers:
cork> 10+2
$0: 12
cork> 3+$0
$1: 15
Hi,
it would be really useful to have a "to radix" command to quickly and temporary convert a number or the result of an expression to a different radix (for example when working with memory address and segments sizes):
cork> 0xCAFE to dec
51966
cork> 0xCAFE + 2 * 8 * 0x20 to dec
52478
cork> 0xCAFE + 2 * 8 * 0x20
0xccfe
cork> ans to bin
0b1100110011111110
cork> 1234 to hex
0x4d2
cork> (0xCAFE + 2 * 8 * 0x20) to oct
0o146376
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.