Skip to content

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Oct 13, 2025

From the suggestion in #59791 (comment).

Fixes #53763.

@KristofferC KristofferC added the DO NOT MERGE Do not merge this PR! label Oct 13, 2025
@KristofferC
Copy link
Member Author

KristofferC commented Oct 13, 2025

I've verified that pasting

julia> 1+1

works in Windows with this PR.

@KristofferC KristofferC requested a review from giordano as a code owner October 14, 2025 07:40
@KristofferC KristofferC changed the title try using julia libuv with ENABLE_VIRTUAL_TERMINAL_INPUT supported bump libuv and ENABLE_VIRTUAL_TERMINAL_INPUT (enables bracket paste in Windows) Oct 14, 2025
@KristofferC KristofferC removed the DO NOT MERGE Do not merge this PR! label Oct 14, 2025
@KristofferC
Copy link
Member Author

KristofferC commented Oct 14, 2025

Result from pasting this big function:

Big function
"""
     wow_so_much_paste()

A ridiculously large function designed to showcase improvements in pasting into the Julia REPL.
This function demonstrates various Julia syntax features, formatting styles, and line lengths
while attempting to be mildly entertaining as it scrolls by on your screen.

# Warning
This function is approximately 500 lines of pure, unadulterated Julia code.
If you're still reading this docstring as it pastes, congratulations on your patience!

# Returns
- A string containing a summary of all the computational "work" done
"""
function wow_so_much_paste()
    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 1: Variable declarations with varying line lengths
    # ════════════════════════════════════════════════════════════════════════════════

    x = 42  # The answer

    extremely_long_variable_name_that_demonstrates_horizontal_scrolling_or_wrapping_behavior = 3.14159265358979323846

    # Here's a short one
    y = 1

    # And here's an absurdly long calculation that definitely exceeds reasonable line length expectations for any sane developer
    result_of_unnecessarily_complex_computation = (x * extremely_long_variable_name_that_demonstrates_horizontal_scrolling_or_wrapping_behavior) + sqrt(abs(sin(x) * cos(y))) - log(1 + exp(x))

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 2: Unicode operators and mathematical expressions
    # ════════════════════════════════════════════════════════════════════════════════

    α = 0.1  # Learning rate (wow, so ML)
    β = 0.9  # Momentum (much optimization)
    γ = 0.99  # Discount factor (very RL)

    # Check if π is approximately equal to 22/7 (spoiler: it's not quite)
    is_pi_close = π  22/7

    # Set operations with unicode
    𝒜 = Set([1, 2, 3, 4, 5])
    ℬ = Set([4, 5, 6, 7, 8])

    union_result = 𝒜  ℬ
    intersection_result = 𝒜 # Function composition with ∘
    f = x -> x^2
    g = x -> x + 1
    composed = f  g

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 3: Array comprehensions and broadcasting (the dot is strong with this one)
    # ════════════════════════════════════════════════════════════════════════════════

    # A simple comprehension
    squares = [i^2 for i in 1:10]

    # A more complex comprehension with filtering
    even_squares = [i^2 for i in 1:20 if i % 2 == 0]

    # Nested comprehension (because why not?)
    matrix = [i * j for i in 1:5, j in 1:5]

    # Broadcasting example (vectorization go brrrrr)
    vec1 = collect(1:100)
    vec2 = collect(101:200)

    broadcasted_sum = vec1 .+ vec2
    broadcasted_product = vec1 .* vec2
    broadcasted_power = vec1 .^ 2

    # Dot syntax with functions
    string_numbers = string.(vec1)

    # Dictionary comprehension
    number_dict = Dict(i => i^2 for i in 1:10)

    # Generator expression (lazy evaluation, because we're efficient like that)
    sum_of_squares = Base.sum(i^2 for i in 1:1000)

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 4: String operations and interpolation
    # ════════════════════════════════════════════════════════════════════════════════

    name = "Julia"
    version = "1.11"

    simple_string = "Hello, $(name)!"

    complex_interpolation = "We're using $name version $version, and the answer is $(x * 2)"

    # Triple-quoted strings (for when you need to get poetic)
    multiline_string = """
    Roses are red,
    Violets are blue,
    Julia is fast,
    And so are you!
    """

    # Raw strings (regex fans unite!)
    regex_pattern = r"^\d{3}-\d{2}-\d{4}$"

    # String with escape sequences
    escaped = "Line 1\nLine 2\tTabbed\nLine 3"

    # Byte array literal
    byte_array = b"Hello, bytes!"

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 5: Control flow - the scenic route through code
    # ════════════════════════════════════════════════════════════════════════════════

    control_flow_result = 0

    # Classic if-else
    if x > 40
        control_flow_result += 10
    elseif x > 30
        control_flow_result += 5
    else
        control_flow_result += 1
    end

    # Ternary operator (for the minimalists)
    bonus = x > 40 ? 100 : 50

    # For loop with various styles
    for i in 1:5
        control_flow_result += i
    end

    # For loop with enumerate
    for (idx, val) in enumerate(squares)
        if idx > 5
            break
        end
        control_flow_result += val
    end

    # While loop (round and round we go)
    counter = 0
    while counter < 10
        counter += 1
        if counter == 5
            continue  # Skip 5 because it's overrated
        end
        control_flow_result += counter
    end

    # Try-catch block (error handling like adults)
    try
        risky_operation = 100 ÷ 0  # Living dangerously
    catch e
        if e isa DivideError
            control_flow_result += 999  # Error code: we tried to divide by zero
        else
            rethrow(e)
        end
    finally
        # This runs no matter what (unlike my motivation on Mondays)
        control_flow_result += 1
    end

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 6: Type annotations and parametric types (getting fancy now)
    # ════════════════════════════════════════════════════════════════════════════════

    # Type annotations on variables
    typed_int::Int64 = 42
    typed_float::Float64 = 3.14
    typed_string::String = "I have a type!"

    # Type annotations with various numeric types
    tiny_int::Int8 = 127
    big_int::Int128 = 123456789012345678901234567890
    complex_num::Complex{Float64} = 3.0 + 4.0im
    rational_num::Rational{Int} = 3//4

    # Union types (type system doing yoga)
    flexible_var::Union{Int, String, Nothing} = nothing
    flexible_var = 42  # Now it's an Int
    flexible_var = "Now it's a String!"  # Flexibility is key

    # Type annotations with arrays
    int_array::Vector{Int} = [1, 2, 3, 4, 5]
    float_matrix::Matrix{Float64} = [1.0 2.0; 3.0 4.0]
    string_vector::Vector{String} = ["hello", "world"]

    # Named tuples (like structs but simpler)
    point = (x=10, y=20, z=30)
    person_data = (name="Alice", age=30, city="Wonderland")

    # Accessing named tuple fields
    person_name = person_data.name
    person_age = person_data.age

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 7: Nested functions and closures (functions within functions)
    # ════════════════════════════════════════════════════════════════════════════════

    function outer_function(x)
        # This variable is captured by the inner function
        captured_value = 100

        function inner_function(y)
            # Closure magic: we can access captured_value
            return x + y + captured_value
        end

        # Return the inner function (first-class functions FTW)
        return inner_function
    end

    closure_instance = outer_function(10)
    closure_result = closure_instance(5)  # Should be 10 + 5 + 100 = 115

    # Anonymous functions (lambdas for the cool kids)
    add_one = x -> x + 1
    multiply = (x, y) -> x * y

    # Anonymous function with multiple lines
    complex_lambda = function(a, b, c)
        temp = a + b
        return temp * c
    end

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 8: Macros (code that writes code - we've gone meta)
    # ════════════════════════════════════════════════════════════════════════════════

    # @time macro (because we care about performance)
    timed_result = @time begin
        sum = 0
        for i in 1:1000000
            sum += i
        end
        sum
    end

    # @inbounds (living dangerously by skipping bounds checks)
    function fast_sum(arr)
        total = 0.0
        @inbounds for i in eachindex(arr)
            total += arr[i]
        end
        return total
    end

    fast_sum_result = fast_sum(vec1)

    # @simd (SIMD vectorization for the speed demons)
    function simd_sum(arr)
        total = 0.0
        @simd for i in eachindex(arr)
            total += arr[i]
        end
        return total
    end

    simd_result = simd_sum(vec2)

    # @show macro (printf debugging, but make it Julia)
    @show x
    @show y

    # @assert (trust, but verify)
    @assert x == 42 "x should be 42, but something went terribly wrong"

    # @eval (evaluating code at... compile time? Runtime? Who knows anymore!)
    @eval beginning_to_question_reality = 42 + 1

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 9: Do-block syntax (for when your functions need functions as arguments)
    # ════════════════════════════════════════════════════════════════════════════════

    # map with do-block
    doubled = map(1:10) do x
        x * 2
    end

    # filter with do-block
    evens = filter(1:20) do x
        x % 2 == 0
    end

    # foreach with do-block (side effects welcome here)
    println("Starting foreach demonstration...")
    foreach(enumerate(["first", "second", "third"])) do (i, item)
        println("  Item $i: $item")
    end

    # open with do-block (automatic resource management)
    # Note: This is just demonstration syntax, not actually creating a file
    # open("nonexistent_file.txt", "w") do file
    #     write(file, "This is how you'd write to a file with automatic closing")
    # end

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 10: Pipe operator and function chaining (data plumbing)
    # ════════════════════════════════════════════════════════════════════════════════

    piped_result = 1:10 |>
                   x -> filter(isodd, x) |>
                   x -> map(y -> y^2, x) |>
                   Base.sum

    # Chaining with multiple operations
    chain_result = "  Hello, World!  " |>
                   strip |>
                   lowercase |>
                   x -> replace(x, "world" => "Julia") |>
                   uppercasefirst

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 11: Splatting and keyword arguments (argument passing acrobatics)
    # ════════════════════════════════════════════════════════════════════════════════

    # Function with keyword arguments
    function greet(name; greeting="Hello", punctuation="!")
        return "$greeting, $name$punctuation"
    end

    greeting1 = greet("Julia")
    greeting2 = greet("Julia", greeting="Hi")
    greeting3 = greet("Julia", greeting="Hey", punctuation="!!!")

    # Splatting a tuple into function arguments
    function add_three(a, b, c)
        return a + b + c
    end

    args_tuple = (1, 2, 3)
    splatted_sum = add_three(args_tuple...)

    # Splatting keyword arguments
    kwargs = Dict(:greeting => "Bonjour", :punctuation => "~")
    greeting4 = greet("Julia"; kwargs...)

    # Varargs function (collect 'em all)
    function add_all_numbers(numbers...)
        return Base.sum(numbers)
    end

    varargs_result = add_all_numbers(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 12: Multiple dispatch examples (Julia's superpower)
    # ════════════════════════════════════════════════════════════════════════════════

    # Define the same function name with different type signatures
    demonstrate_dispatch(x::Int) = "You passed an Integer: $x"
    demonstrate_dispatch(x::Float64) = "You passed a Float64: $x"
    demonstrate_dispatch(x::String) = "You passed a String: $x"
    demonstrate_dispatch(x::Int, y::Int) = "You passed two Integers: $x and $y"
    demonstrate_dispatch(x, y) = "You passed something else: $x and $y"

    dispatch_result1 = demonstrate_dispatch(42)
    dispatch_result2 = demonstrate_dispatch(3.14)
    dispatch_result3 = demonstrate_dispatch("hello")
    dispatch_result4 = demonstrate_dispatch(1, 2)
    dispatch_result5 = demonstrate_dispatch(1, "mixed")

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 13: Pattern matching and destructuring (unpack all the things)
    # ════════════════════════════════════════════════════════════════════════════════

    # Tuple destructuring
    tuple_data = (1, 2, 3)
    a, b, c = tuple_data

    # Array destructuring
    array_data = [10, 20, 30, 40, 50]
    first, second, rest... = array_data

    # Nested destructuring
    nested = ((1, 2), (3, 4))
    (x1, y1), (x2, y2) = nested

    # Dictionary destructuring (sort of)
    person = Dict("name" => "Alice", "age" => 30, "city" => "Wonderland")
    name_val = person["name"]
    age_val = person["age"]

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 14: More array operations (arrays all the way down)
    # ════════════════════════════════════════════════════════════════════════════════

    # Array concatenation
    arr1 = [1, 2, 3]
    arr2 = [4, 5, 6]
    concatenated = [arr1; arr2]  # Vertical concatenation

    # Horizontal concatenation
    matrix1 = [1 2; 3 4]
    matrix2 = [5 6; 7 8]
    hcat_result = [matrix1 matrix2]

    # Array slicing
    big_array = collect(1:100)
    slice1 = big_array[1:10]
    slice2 = big_array[end-9:end]
    slice3 = big_array[1:2:20]  # Every other element

    # Multidimensional arrays
    tensor = rand(3, 4, 5)

    # Array reduction operations
    max_val = maximum(big_array)
    min_val = minimum(big_array)
    avg_val = Base.sum(big_array) / length(big_array)

    # Any and all
    has_even = any(x -> x % 2 == 0, big_array)
    all_positive = all(x -> x > 0, big_array)

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 15: Ranges and iterators (lazy evaluation station)
    # ════════════════════════════════════════════════════════════════════════════════

    # Various range types
    simple_range = 1:10
    range_with_step = 1:2:20
    float_range = 0.0:0.1:1.0

    # Reverse range
    countdown = 10:-1:1

    # Collecting ranges
    collected_range = collect(simple_range)

    # zip iterator (marry your arrays)
    names = ["Alice", "Bob", "Charlie"]
    ages = [30, 25, 35]
    zipped = collect(zip(names, ages))

    # enumerate (because counting is hard)
    for (i, name) in enumerate(names)
        println("Person $i: $name")
    end

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 16: More complex nested structures (inception-level nesting)
    # ════════════════════════════════════════════════════════════════════════════════

    nested_dict = Dict(
        "level1" => Dict(
            "level2" => Dict(
                "level3" => Dict(
                    "level4" => "You've gone too deep!"
                )
            )
        )
    )

    nested_arrays = [
        [
            [1, 2, 3],
            [4, 5, 6]
        ],
        [
            [7, 8, 9],
            [10, 11, 12]
        ]
    ]

    # Complex comprehension with multiple levels
    complex_comp = [
        [
            (i, j, k)
            for k in 1:3
        ]
        for i in 1:2
        for j in 1:2
    ]

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 17: Some actual computations (pretending to do real work)
    # ════════════════════════════════════════════════════════════════════════════════

    # Fibonacci sequence
    function fib(n)
        if n <= 2
            return 1
        else
            return fib(n-1) + fib(n-2)
        end
    end

    fib_result = [fib(i) for i in 1:10]

    # Factorial
    factorial(n) = n <= 1 ? 1 : n * factorial(n-1)

    fact_result = factorial(10)

    # Prime number check
    function is_prime(n)
        if n < 2
            return false
        end
        for i in 2:isqrt(n)
            if n % i == 0
                return false
            end
        end
        return true
    end

    primes_under_100 = [i for i in 1:100 if is_prime(i)]

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 18: ASCII art intermission (because we deserve a break)
    # ════════════════════════════════════════════════════════════════════════════════

    ascii_art = """

           /\\_/\\
          ( o.o )
           > ^ <
          /|   |\\
         (_|   |_)

    This cat is judging your code quality.
    The cat is... satisfied (for now).

    """

    println(ascii_art)

    # ════════════════════════════════════════════════════════════════════════════════
    # SECTION 19: Final computations and aggregations (the grand finale approaches)
    # ════════════════════════════════════════════════════════════════════════════════

    # Let's compute something that looks impressive
    matrix_a = rand(10, 10)
    matrix_b = rand(10, 10)

    # Matrix multiplication
    matrix_product = matrix_a * matrix_b

    # Element-wise operations
    matrix_elementwise = matrix_a .* matrix_b

    # Matrix transposition
    matrix_transposed = matrix_a'

    # Determinant (if we had LinearAlgebra loaded, but we'll pretend)
    # det_value = det(matrix_a)

    # Create a summary of all our "hard work"
    summary = """

    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║                          COMPUTATION SUMMARY                                   ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

    📊 Basic Statistics:
       • Initial x value: $x
       • Final control flow result: $control_flow_result
       • Closure result: $closure_result
       • Piped result: $piped_result

    🎯 Array Operations:
       • Number of squares computed: $(length(squares))
       • Sum of squares (1-1000): $sum_of_squares
       • Fast sum result: $fast_sum_result
       • SIMD sum result: $simd_result

    🔢 Mathematical Results:
       • Is π ≈ 22/7? $is_pi_close
       • 10th Fibonacci number: $(fib_result[end])
       • Factorial of 10: $fact_result
       • Primes under 100: $(length(primes_under_100))

    📝 String Operations:
       • Chain result: $chain_result
       • Greeting 1: $greeting1
       • Greeting 4: $greeting4

    🎭 Multiple Dispatch Demonstrations:
       • Dispatch 1: $dispatch_result1
       • Dispatch 2: $dispatch_result2
       • Dispatch 3: $dispatch_result3
       • Dispatch 4: $dispatch_result4
       • Dispatch 5: $dispatch_result5

    🔀 Set Operations:
       • Union: $union_result
       • Intersection: $intersection_result

    📦 Named Tuple Values:
       • Point x-coordinate: $(point.x)
       • Person name: $(person_data.name)

    ⚡ Performance Notes:
       • Used @time macro: ✓
       • Used @inbounds optimization: ✓
       • Used @simd vectorization: ✓
       • Questioned reality with @eval: ✓

    🎨 Syntax Showcase Checklist:
       ✓ Unicode operators (∈, ∪, ∩, ∘, ≈)
       ✓ Broadcasting with dots
       ✓ Array comprehensions
       ✓ Dictionary comprehensions
       ✓ Generator expressions
       ✓ String interpolation
       ✓ Multiline strings
       ✓ Type annotations
       ✓ Named tuples
       ✓ Union types
       ✓ Complex numbers
       ✓ Closures
       ✓ Anonymous functions
       ✓ Macros
       ✓ Do-block syntax
       ✓ Pipe operator
       ✓ Splatting
       ✓ Keyword arguments
       ✓ Varargs
       ✓ Multiple dispatch
       ✓ Destructuring
       ✓ Control flow (if/else, for, while, try/catch)
       ✓ Pattern matching
       ✓ Nested structures
       ✓ ASCII art (most important)

    ╔════════════════════════════════════════════════════════════════════════════════╗
    ║  "Talk is cheap. Show me the code." - Linus Torvalds                           ║
    ║  "This function is neither cheap nor full of talk. It's just... long."         ║
    ╚════════════════════════════════════════════════════════════════════════════════╝

    """

    return summary
end;

Before:

Screen.Recording.2025-10-14.at.09.55.22.mov

After:

Screen.Recording.2025-10-14.at.09.56.11.mov

The current windows paste also seems to have some issues with getting the result exactly right (perhaps something to do with the auto indentation?). The list and frame below are erronously indented:

image

@KristofferC KristofferC force-pushed the kc/julia-uv_term branch 4 times, most recently from b95a2fb to 0ba0c50 Compare October 14, 2025 11:39
@KristofferC KristofferC merged commit f73700d into master Oct 14, 2025
8 checks passed
@KristofferC KristofferC deleted the kc/julia-uv_term branch October 14, 2025 14:11
@topolarity
Copy link
Member

Works great! Thanks @KristofferC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bracketed Paste Mode is not enabled on Windows

2 participants