Coder Social home page Coder Social logo

xoofx / kalk Goto Github PK

View Code? Open in Web Editor NEW
294.0 10.0 16.0 10.86 MB

kalk is a powerful command line calculator app for developers.

Home Page: https://kalk.dev

License: BSD 2-Clause "Simplified" License

C# 99.62% CSS 0.03% HTML 0.01% JavaScript 0.07% SCSS 0.19% Inno Setup 0.09%
calculator tool

kalk's People

Contributors

coenm avatar ficture7 avatar scottbilas avatar xoofx 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

kalk's Issues

Error converting HEX to DECIMAL

KALK 0.4.0 is not converting well hex numbers to decimal.

For instance 0x0123 should be 291:

image

It only happens when the HEX number is expressed with odds digits...

Wish: When syntax error happens, put cursor at the end of broken expression

Wish

First of all, thank you very much for the excellent tool you created! I used basics of it only, but already found it amazing.

One thing which immediately hit me, is that in case of error the cursor is put at the beginning of the error expression, not the end. For example if you type

bin something

the cursor is put at the beginning of something:

image

That feels "unexpected" to me. It's a bit unusual to use "delete" button to correct the error, not the "backspace" one. It's very difficult for me though to explain why exactly I feel the current behavior non-natural. Like I would naturally have an intent to look for an error left to the cursor, not right. And also I have intuition to fix error to the left, not to the right.
Could be because in IDE you would usually have the whole error selected with the cursor at the end - so that's where I got used to that.

I do not have strong arguments in favor of suggested behavior change and I did not test how it would feel if that would be different. But decided to drop an issue in case I'm not the only one or you yourself thought about it as well ๐Ÿ˜ƒ

Idea

In case AST underneath allows to precisely track position, one of the ideas could be to have something like this:
https://twitter.com/firstdrafthell/status/1427936354214764548

Then repeat the prompt again with the cursor at the end. This way it's clear what the boundaries of the error are even in case when broken expression has multiple words.

Ctrl-D to exit (Linux and macOS)

Unix-derived operating systems like Linux and macOS use Ctrl-D (^D, EOT, end-of-transmission) as input terminator, with the typical behavior of closing a terminal shell when typed after a prompt. Also the Python CLI, that shares the prompt (>>>) with kalk, closes on Linux and macOS when Ctrl-D is typed right after the prompt (after writing ^D where the cursor was). Kalk could use ^D on Linux and Mac just like it uses ^Z on Windows.

big-endian bin

The string containing the binary representation output by bin, which can also be its input, is divided into bytes written least-significant to most-significant left to right, i.e., supposing memory locations increase left to right, in "little-endian" (LE) order. This order is the most widespread order nowadays, but to better understand the constituents of the representation the "big-endian" (BE) order is definitely more intuitive โ€“ especially for floating-point numbers. BTW, it can also be interpreted as the LE order with memory addresses increasing right to left.
I don't know what the BE equivalent of the bin function could be called, or if other mechanisms to select the BE representation could be devised, but let me call it for now the bebin function. Example calls:

>>> bebin 259
# bebin(259)
out = "00000000 00000000 00000001 00000011"
>>> bebin "00000000 00000000 00000001 00000011"
# bebin("00000000 00000000 00000001 00000011")
out = 259
>>> bebin 1.25
# bebin(1.25)
out = "00111111 11110100 00000000 00000000 00000000 00000000 00000000 00000000"

Add command line options for e.g processing files and others

kalk is a command line app but doesn't have options to use it outside of its interactive mode

  • e.g --file=input.kalk to process an input file
  • or to print its version --version
  • or to predefine some variables passed from the command line e.g `--set="x=1"
  • or to evaluate an expression from the command line --eval="x = 1; x + 2"
  • or simply --help to print all these options

We need to define what we can allow to do here.

Many functions fail for unknown reasons, error "No parameterless constructor defined."

This is what I'm seeing on debian sid under WSL:

>>> cos 45
Cannot dynamically create an instance of type 'Kalk.Core.KalkDoubleValue'. Reason: No parameterless constructor defined.

I've verified this with the trig functions, log, sqrt, exp, round, etc. abs produces a similar message referencing 'Kalk.Core.KalkCompositeValue'.

I'm not sure why this is happening, and my .NET Core 7 installation seems fine otherwise. Any particular information I should send you for this one? Not sure what would be helpful.

Crashed on start

  • macOS 13.0.1 on M2 (arm64)
  • Installed from Homebrew.
  • Running zsh with Oh My Zsh framework (tried both Terminal app and iTerm2).
  • after running kalk :
    [1] 33491 killed kalk

Running kalk.exe standalone from explorer has broken prompts in output

If I run kalk.exe straight from explorer it pops up a command window but the color codes seem to be broken and display as strings:

image

When I run this from e.g. conemu it works fine. Not sure if this is something about detecting console capabilities to turn off the color output or what might be the difference?

image

I'm not sure what information you might need from me - this is 0.1.1 downloaded straight from https://kalk.dev . I can build from source and debug or provide anything else you might need since I imagine this is system-specific and not a general problem.

btw I'm not sure if this is a separate unrelated issue but my gut feeling tells me it's too coincidental and it's probably related to the same thing. Even in conemu if I type in an unrecognised command it seems to break the prompt from then on:

image

And then if I type I typed this just once I get:

image

If that needs to be split into a separate issue please let me know, I didn't want to file two bugs since it felt like probably the same root cause.

Add terminal setup color guidance for good experience with kalk

kalk is relying on standard ANSI escape code colors to select the colors for syntax highlighting.

We don't want necessarily to use other colors (e.g user defined with full RGB escape sequences) but would like to only rely on these standard escape code.

The supported colors are the following, and kalk is using only a subset of them:

  • Black
  • Red -> kalk errors
  • Green
  • Yellow -> kalk units
  • Blue
  • Magenta
  • Cyan -> kalk built-in functions/values
  • White -> kalk anything else
  • Bright Black (Gray)
  • Bright Red
  • Bright Green -> kalk comments
  • Bright Yellow -> kalk keywords
  • Bright Blue
  • Bright Magenta
  • Bright Cyan -> kalk VerbatimString
  • Bright White -> kalk name followed by a :

The code involved is here:

private ConsoleStyle? GetStyle(int index, Token token, string text, bool isPreviousNotDot, List<Token> tokens)
{
switch (token.Type)
{
case TokenType.Integer:
case TokenType.HexaInteger:
case TokenType.BinaryInteger:
case TokenType.Float:
return ConsoleStyle.Bold;
case TokenType.String:
case TokenType.VerbatimString:
return ConsoleStyle.BrightCyan;
case TokenType.Comment:
case TokenType.CommentMulti:
return ConsoleStyle.BrightGreen;
case TokenType.Identifier:
var key = token.GetText(text);
if (isPreviousNotDot)
{
if ((index + 1 < tokens.Count && tokens[index + 1].Type == TokenType.Colon))
{
return ConsoleStyle.BrightWhite;
}
if (ScriptKeywords.Contains(key))
{
// Handle the case where for ... in, the in should be marked as a keyword
if (key != "in" || !(index > 1 && tokens[index - 2].GetText(text) == "for"))
{
return ConsoleStyle.BrightYellow;
}
}
if (Builtins.ContainsKey(key) || ValueKeywords.Contains(key))
{
return ConsoleStyle.Cyan;
}
else if (Units.ContainsKey(key))
{
return ConsoleStyle.Yellow;
}
}
return ConsoleStyle.White;
default:
return null;
}
}

We should add some guidance to the documentation on how to configure these colors (e.g in new Windows terminal)

Accessorily, do we need to improve the syntax highlighting?

The .NET global tool version needs lzma.dll

Well, sorry, but it's time for the first issue ๐Ÿ˜…

I tried to install kalk as a .NET tool, and here's the console output:

C:\Users\lucas>dotnet tool install --global kalk --version 0.1.0
You can invoke the tool using the following command: kalk
Tool 'kalk' (version '0.1.0') was successfully installed.

C:\Users\lucas>kalk
Error:
  An assembly specified in the application dependencies manifest (kalk.deps.json) was not found:
    package: 'Packaging.Targets', version: '0.1.189'
    path: 'runtimes/win7-x64/native/lzma.dll'

I have the .NET SDK installed through a VS 2019 build tools installation on this machine.

Thanks for this tool BTW! ๐Ÿ˜„

SHIFT+END on Linux WSL generates an escape sequence

When pressing SHIFT+END with the following program:

using System;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.TreatControlCAsInput = true;
            while (true)
            {
                var key = Console.ReadKey(true);
                Console.WriteLine($"Key: {key.Key} Modifiers: {key.Modifiers} Char: {(key.KeyChar < ' ' || (int)key.KeyChar >= 126 ? "0x" + ((int)key.KeyChar).ToString("x2") : key.KeyChar.ToString())}");
                if (key.Key == ConsoleKey.C && (key.Modifiers & ConsoleModifiers.Control) != 0)
                {
                    break;
                }
            }
        }
    }
}

It generates the following sequence on Linux:

Key: Escape Modifiers: 0 Char: 0x1b
Key: D1 Modifiers: 0 Char: 1
Key: 0 Modifiers: 0 Char: ;
Key: D2 Modifiers: 0 Char: 2
Key: F Modifiers: Shift Char: F

instead of generating the following on Windows:

Key: End Modifiers: Shift Char: 0x00

In kalk, it's breaking the start selection + move cursor to end, while SHIFT+HOME is working just fine.

So it's either a bug in .NET or in WSL. I haven't checked this in a VM/real Linux so see how it behaves...

Build instructions in README?

It would be nice to have instructions on how to build, along with essential dependencies, laid out in the readme.

Add support for ARM Hardware Intrinsics

kalk should be able to run on an ARM device/OS, so we should be able to export all the ARM intrinsics in a similar way Intel HW Intrinsics have been exposed.

Add tests for all Intel Hardware Intrinsics

There are currently no tests for testing that these intrinsics are working (and we have 730+ of them)

We should at least generate automated input values to check that they are all running fine at least.
We could then manually validate some of them regarding expected results.

[linux/WSL] clipboard only works if powershell.exe and/or clip.exe is in path

Which is to say, if the Windows path has been duplicated into WSL, and while that's the default, it's not a guarantee.

(I prefer to turn off path copying because my Linux path is long enough without cramming all of my Windows path, relevant or not, into it. It also generates WSL errors when path translation can't cope with network paths.)

Maybe it would be possible to invoke these with their full paths, based on %SystemRoot% or the location of the "/Windows" directory under /mnt/c or other drive letter?

Fix keyboard shortcuts on macOS

All the CTRL+left, CTRL+right are not working.

We should maybe replace CTRL by ALT on macOS (because the %command+left is used for switching between windows).

Ubuntu 21.04 and libicu67

Hi Alexandre Mutel(@xoofx),

I've tried to install your latest *.deb package, at version 0.4.0, on my Ubuntu 21.04 64b and it doesn't want to, due to the fact that the package is relying on <= libicu66 and my Ubuntu is on libicu67.

Could I ask that you confirm that it can be installed under libicu67?

Many thanks in advance!!

Cheers,
Gus

Currencies module fails do download rates

Run import Currencies and it fails with the following error:

>>> import Currencies
# 2 functions successfully imported from module `Currencies`.
# Downloading rates from https://api.exchangeratesapi.io/latest
Unable to download rates. Reason: Unable to find `rates` from returned JSON.
# Using rates defined as of 2020-05-08.

I've checked the endpoint itself and it seems to be alive.

command features to save to output.

Is a good idea, but you have has a lack.
If I want to create variables, data structures then you will have to find a way to send them in text format to a file and not to copy/paste.
Using a set in settings
Example:

>>> a = bool2x2
# a = bool2x2
a = bool2x2(false, false, false, false)
      # col 0           1           / row
      bool2(false     , false     ) # 0
      bool2(false     , false     ) # 1

Use a command to set patterns in settings to have a good output.

  1. column names and other items that are in the comments area are prefixed with #, you could change this with a setting that can be set for C #: //
  2. you could output as a text file that already contains a default python, C #, or shader file type format that can then be used and modified by an I.D.E.

Maybe you can try to do it with :
# Modules (e.g import Files) - All, Csv, Currencies, Files, HardwareIntrinsics, StandardUnits, Strings, Web

It solves it, then you need to fulfill with simple tutorials ...
Thank's for share.

Add quaternion + all matrices helpers

kalk is missing quaternions and all matrices helpers (rotate/scale/translate), so it's a bit cumbersome today to perform quick calculations with 3D stuffs

Ignore currency and thousand separators

Not sure if this is compatible with the goals of this project, but I've always wanted a command line calculator that ignored currency symbols (e.g. $) and thousand separators (, in the US, . in many other countries).

So for example:

>>> $1,000.00 / 4
$250

Ability to type .3 without 0

Hi

Fantastic app! I wanted to suggest adding ability to type the decimal value without a leading zero. For example, .3 instead of 0.3.

Would this be possible?

Thank you!
Dax

Provide a Chocolatey package?

kalk is distributed via:

  • Windows: Windows Store
  • Linux: deb/rpm packages for Linux to install manually
  • macOS: brew
  • Alternatively for all platforms: .NET global tool

Should we provide a Chocolatey package? For part of the packaging above, kalk is relying on Packaging.Targets

Ctrl-C quits application

When I get the syntax wrong, I get some helpful red text but the cursor remains on the original line. Unfortunately, my shell muscle memory makes me hit Ctrl-C which exits the app and I loose everything from my current session.

Kalk opens a dedicated window. AFAIK it's not an interactive shell (like Python or some other compilers / environments) that can be run via terminal where you might need to "abort".

I don't think Ctrl-C should quit the application without a warning. Preferably it would not do anything (except if something is selected, then of course it should copy as it currently does).

Bitwise operations - add one's complement, alternative representations and improve documentation

  1. I could not find any information in the docs about one's complement. The other basic bitwise operations work as expected (&, I, ^), but neither "not", nor "~", nor "!" work for me.

  2. I think it would intuitive to have alternative operators as well in the form of "and", "or", "xor" and "not"
    Similar to this https://en.cppreference.com/w/cpp/language/operator_alternative

  3. Binary shifts are not really mentioned in the documentation. kalk's >> is an arithmetic shift as far as I can see. Might be worth clarifying.

Handle Celsius/Kelvin and other +/- delta unit conversions

kalk is supporting complex conversions with multiple units, but only if they are multiplied or divided or powered.

But today, kalk is not able to express simple conversions like:

[ยฐC] = [K] โˆ’ 273.15

The code involved is in KalkExpressionSimplifier.cs is relatively basic to simplify units operations (e.g C * km / h can be reduced to C * m / s) but I'm not sure on how to handle the +/- delta easily.

For example a unit ยฐC/m, how would be expressed the right side? (K-273)/m?

i^3 returns 0

i3 returns 0 while it should be -i
image

Using kalk 0.11.0

please move executable link in APT package from /usr/local/bin/kalk to /usr/bin/kalk

(Sorry, I'd have submitted this as a pull request, but I couldn't find the apt packaging files.)

A very minor issue, but APT packaging standards make a point of insisting that packages touch nothing inside the /usr/local/* hierarchy, as that's supposed to be reserved for things the admin installed locally, meaning compiled from source. Having the link in /usr/local/* can confuse some management tools.

(And, after all, as a packaged app, kalk has earned its place in /usr/bin ๐Ÿ˜ .)

Thanks!

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.